我编写了一个基于SERVLET的计数器,请问怎么样用JSP显示出来

xuxiaodong4 2003-08-25 09:38:31
源程序如下:
FileCounter.java
package counter;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class FileCounter extends HttpServlet {
int counter;


public void init(ServletConfig config) throws ServletException {

super.init(config);
}



public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

String id=request.getParameter("id");

File file=new File("D:/FileCounter"+id+"counter.txt");

RandomAccessFile raf;

if(!file.exists()){

raf=new RandomAccessFile(file,"rw");
counter=1;
raf.writeInt(counter);
raf.close();
}
else{
raf=new RandomAccessFile(file,"rw");
counter=raf.readInt();
counter++;
raf.seek(raf.getFilePointer()-1);
raf.write(counter);
raf.close();
}
response.setContentType("text/html");

PrintWriter out = new PrintWriter (response.getOutputStream());

out.print("本页已有"+counter+"</font>人次造访");

out.close();
}


}
...全文
45 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧