I feel that the database is not very fast, so I made a text counter, and the servlet, in fact, there are many code online. Then Win2000S Tomcat5.0 is passed. The code is as follows:
Import javax.servlet. *; import javax.servlet.http. *; import java.io. *; import java.util. *;
public class counter extends HttpServlet {private static final String CONTENT_TYPE = "text / html; charset = GBK"; String countNums [] = null; String [] = countNum null; String counts [] = null; String temper = null; int count = 0; int counted = 0; string path = "e: //counter.txt"; // You can define the path to the file, set the initial value (INT!) INT Numlen = 0;
// Initialize Global Variables Public Void Init () THROWS ServleTexception {} // Process The Http Get Request Public Void Doget (HttpservletRequest Request, HttpservletResponse Response) THROWS
ServletException, IOException {response.setContentType; printwriter out = response.getwriter (); counts = this.counting (); for (int i = 0; i } // Clean Up Resources Public void destroy () {} public void dopost (httpservletRequest request, httpservletResponse response) throws servletexception, ioException {doget (Request, response); public String [] counting () throws IOException {// remove by-digital try {FileReader fr = new FileReader (path); BufferedReader br = new BufferedReader (fr); String Line = br.readLine ();! if (Line = null ) {TEMPER = line; Numlen = line.Length (); countnums = new string [number]; countnum = new string [number]; for (int L = 0; l <= Numlen - 1; l ) {countnum [l ] = Line.substring (L , L); l -; countnums [l] = " "; // Put the counter folder containing the picture under WebApps, the image format is JPG, the file name is 0-9; } Br.close (); fr.close (); this.addnum ();}} catch (Exception exception) {System.out.println ( "Init Error:" exception);} return countNums;} public void addNum () {try {File txt = new File (path); PrintWriter out = new PrintWriter (new FileWriter (TXT)); count = integer.parseint (Temper.tostring ()); counters = count 1; // counter adds an out.print (counters); // Write file counter.txt out.close () ;} Catch (ioexception e) {system.out.print (e.tostring ());}}}