我这个方法不知道行不行,你的链接肯定要指向一个jsp文件或者servlet,可以在被链接的文件里取的参数,然后通过文件操作来读写,这个方法很苯。或者设置一个application属性值,我把第一种方法写出来吧。
比如:有a.html或者a.jsp
<%@ page contentType="text/html;charset=GB2312" %>
<html>
<body>
<tr><a href="countservlet?clickcount=1">链接到b.jsp</a></tr>
</body>
</html>
然后有一个b.jsp文件
import javax.servlet.*;
import javax.servlet.Http.*;
import java.io.*;
public class CountServlet extends HttpServlet
{
BufferedReader bin=null;
BufferedWriter bout=null;
int clickcount;
int totalclickcount;
public void service(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
{
reponse.setContentType("text/html;charset=GB2312");
PrintWriter out=response.getWriter();
clickcount=(int)request.getParamter("clickcount");
try{
bin=new BufferdeReader(new InputStreamReader(new FileInputStream("count.txt")));
bout=new BufferedWriter(mew OutputStreamWriter(new FileoutputStream("count.txt")));
totalclickcount=clickcount+(int)bin.readlian();//假定该文件已经有数据,因为是一个数字,所以我用做是否的while循环
out.println("<html><body><tr>");
out.println("被点击了"+allclickcount+"次");
out.println("</tr></body></html>");
bout.writeLine((String)allclickcount,0,(String)allclickcount.lengh())
}
catch(Exception e){System.out.println("发生错误");}
}
}
比如:有a.html或者a.jsp
<%@ page contentType="text/html;charset=GB2312" %>
<html>
<body>
<tr><a href="countservlet?clickcount=1">链接到b.jsp</a></tr>
</body>
</html>
然后有一个b.jsp文件
import javax.servlet.*;
import javax.servlet.Http.*;
import java.io.*;
public class CountServlet extends HttpServlet
{
BufferedReader bin=null;
BufferedWriter bout=null;
int clickcount;
int totalclickcount;
public void service(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
{
reponse.setContentType("text/html;charset=GB2312");
PrintWriter out=response.getWriter();
clickcount=(int)request.getParamter("clickcount");
try{
bin=new BufferdeReader(new InputStreamReader(new FileInputStream("count.txt")));
bout=new BufferedWriter(mew OutputStreamWriter(new FileoutputStream("count.txt")));
totalclickcount=clickcount+(int)bin.readlian();//假定该文件已经有数据,因为是一个数字,所以我用做是否的while循环
out.println("<html><body><tr>");
out.println("被点击了"+allclickcount+"次");
out.println("</tr></body></html>");
bout.writeLine((String)allclickcount,0,(String)allclickcount.lengh())
}
catch(Exception e){System.out.println("发生错误");}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货