650) this.width=650; "src=" Http://183.61.143.148/group1/M00/02/64/tz2PlFRHUsjQBhYbAABF9xZkBho978.jpg "style=" border:0px; "/>
Using Java to implement a simple picture of the counter, run diagram:
650) this.width=650; "src=" Http://183.61.143.148/group1/M00/02/64/tz2PlFRHUZTj-_rMAAC4cE2FPVU822.png "style=" border:0px; "/>
to learn more about Java, you can click on the Java EE software engineer "to learn.
<%@ page contenttype= "text/html;charset=gb2312"%>
<%@ page language= "java" import= "java.io.*"%>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title> counters </title>
<%!
Synchronizing Update counters
synchronized void counter () {
ServletContext Application=getservletcontext (); Constructing application objects (optional)
String Szpath=application.getrealpath ("/"); Get current path
szpath=szpath+ "Hits.txt"; Counter file 0-9999999999999 ...
String szrecord= ""; Count String
int nrecord=0; Count int
try{
BufferedReader file=new BufferedReader (New FileReader (szpath));
Szrecord=file.readline (); Read Counter file
}
catch (Exception e) {
System.out.println (e);
}
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 the file. This method of frequently writing files to save the count is undesirable.
Pw.close ();
}
catch (Exception e) {
System.out.println (e);
}
}
%>
<%
Display counter
if (Session.isnew ()) {//If it is a new session
Counter ();
}
String Path=application.getrealpath ("/");
Out.println (Path);
String szpath=path+ "Hits.txt";
String szrecord= "";
BufferedReader file=new BufferedReader (New FileReader (szpath));
try{
Szrecord=file.readline ();
if (szrecord==null) {
szrecord= "0";
}
}
catch (Exception e) {
System.out.println (e);
}
Displaying a 7-bit digital GIF image
String szout= "<body topmargin= ' 0 ' leftmargin= ' 0 ' > Current traffic:";
int i=0;
int K=7-szrecord.length (); Number of "0"
for (i=0;i<k;i++) {//display "0"
szout=szout+ "}
For (I=0;i<szrecord.length (); i++) {//Show non-"0"
szout=szout+ "}
szout=szout+ "</body>";
Out.println (szout);
%>
to learn more about the Java Learning program, you can focus on e Mentor .
Simple picture counters can also be implemented in Java