| |
做一个带有beans的文字计数器 访问计数器程序:counter.java
package counter; import java.io.*; public class counter { public string path=""; public string docount() throws filenotfoundexception { bufferedreader file; string countfile=path; file=new bufferedreader(new filereader(countfile)); string readstr=""; int writestr=1; try { readstr=file.readline(); } catch(ioexception e) { system.out.println("读取数据错误."); }
if(readstr=="") readstr="没有任何记录"; else { writestr=integer.parseint(readstr)+1; }
try { printwriter pw=new printwriter(new fileoutputstream(countfile)); pw.println(writestr); pw.close(); } catch(ioexception e) { system.out.println(e.getmessage()); } return readstr; } }
counter.jsp代码如下: <html> <head> <t99vle> counter </t99vle> </head> <body> <jsp:usebean id="counter" scope="request" class="counter.counter" /> <%@ page contenttype="text/html;charset=gb2312"%> <% counter.path="count.txt"; string count=counter.docount(); %> <p align="center"> <h3 align="center"><font color="#993300" size="5">您好!您是本系统的第 <font color="ff0000"><%=count%> </font> 名访问者!</font></h3> </body> </html>
|
|