JSP counter
The JSP counter that will be used in many places, I hope to help everyone, do it as a collection. <% @ Page ContentType = "Text / HTML; Charset = GB2312"%> <% @ page language = "java" import = "java.io. *"%>
<%! // Synchronous Update Counter Synchronized Void Counter () {servletContext Application = GetServletContext (); // Constructs Application Object (Optional) String Szpath = Application.getRealPath ("/"); // Get Current Path Szpath = Szpath "hits.txt"; // counter file 0-99999999999999 ... String szrecord = ""; // count string int nRecord = 0; // Notes INT Try {BufferedReader File = New BufferedReader (New FileReader (Szpath) ); Szrecord = file.readLine (); // read counter file} catch (ioException e) {E.PrintStackTrace (System.err);} if (szrecord == null) szrecord = "0"; // If the counter File is empty
NRecord = java.lang.integer.parseint (szrecord) 1; // counter 1 try {file f = new file (szpath); PrintWriter PW = New PrintWriter (New FileWriter (f)); PW.Print (NRECORD) ; // Write files PW.Close ();} catch (ooException e) {system.out.println (e);}}%>