我做了个论坛,在首页通过点击标题进入文章,点击标题时,链接到servlet跳转页面,成功跳转时同时执行点击数的更新,当进入文章的页面后,只是不停地刷新,点击数就上去了。这是为什么,如何控制?请各位高手赐教!谢谢!

解决方案 »

  1.   

    你可能是想实现只在点击连接是刷新点击率,而刷新页面时点击率不变。我的思路:链接加上参数,如<a href="/servlet?add=1">abc</a>
    在Servlet里获取参数add,如果等于1,那么点击率加1,否则不加,但是跳转时要注意不要url上加add参数了,这样跳转后的url就没有add了,如:.../abc.jsp
    随他怎么刷,Servlet都能正确判断。
      

  2.   

    三楼师兄说的我试过了,还是不能控制。现附原代码如下,希望能得到更仔细的指点。
    package accp.bbs.servlet;import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.ArrayList;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;import accp.bbs.bean.BBSReplyBean;
    import accp.bbs.bean.BBSTopicBean;
    import accp.bbs.dao.daoimp.BBSTopicImp;
    import accp.bbs.dao.daoimp.BBSUserInfoImp;public class contentShowServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    doPost(request, response);
    } public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    HttpSession session = request.getSession();
    int uid=0;
    if(session.getAttribute("uid")!=null)
                    {
    uid=(Integer)session.getAttribute("uid");//此处判断是否是会员登录
    }
    String tid = request.getParameter("tid");//获是标题编号
    int tuid=Integer.parseInt(request.getParameter("tuid"));//获得作者编号
    int Tsid = Integer.parseInt(request.getParameter("Tsid"));//获得版块编号
    session.setAttribute("Tsid", Tsid);
    if (tid != null) 
                   {
    int path = Integer.parseInt(tid);
    if(uid!=tuid)
                         {
    // 这里是在有人点击标题浏览文章时,将文章的点击率更改,但登录后点击本人的文章不能更改
    BBSTopicImp bim = new BBSTopicImp();
    int a = bim.modifyBBSTopic(path);//调用执行点击数更新的方法
    BBSUserInfoImp userimp=new BBSUserInfoImp();
    int b=userimp.modifyBBSUserInfo(tuid);//同时累加作者积分
    if (a != 0&&b!=0)
                            {//跳转文章所在的页面
    request.getRequestDispatcher(
    "../pages/contentShow.jsp?tid=" + path+"&tsid="+Tsid).forward(
    request, response); //进入文章所在的页面后进行刷新,就会执行点击数更新的方法
    }
    }else{
    request.getRequestDispatcher(
    "../pages/contentShow.jsp?tid=" + path+"&tsid="+Tsid).forward(
    request, response);
    }

    }
    }
    }
      

  3.   

    判断访问的UIL是否是主页还是当前页