我想实现当我进JSP里登陆后,显示当前用户登陆多少次的记录。
但我Servlet里的判断不知道怎么写。
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { response.setContentType("text/html;charset=GBK");
request.setCharacterEncoding("GBK");
String txtName = request.getParameter("txtName");
String txtPwd = request.getParameter("txtPwd");
HttpSession session = request.getSession();
}
谁能帮我解答下阿?

解决方案 »

  1.   

    不用外部存储怎么能纪录用户的登录次数???不太明白楼主的意思。
    String txtName = request.getParameter("txtName");
    int cnt = getLoginCount(txtName);//得到该用户的登录次数,用外部存储
    cnt++;
    writeCount(cnt);//增加一次后重新记入
    //现实登陆次数cnt
      

  2.   

    如果你的用户表有登录次数这个字段
    在用户(登录名,密码)提交后,验证通过后,更新登录次数并取出,用request.setAttribute()显示在相应页面
    如果没有这个字段,你可以将登录次数写在文件里,txt,xml都可以;也可以写在cookie里,如果客户端支持的话。
      

  3.   

    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException { response.setContentType("text/html;charset=GBK");
    request.setCharacterEncoding("GBK");
    String textfield = request.getParameter("textfield");
    String textfield2 = request.getParameter("textfield2");
    HttpSession session = request.getSession();
    String count = (String) session.getAttribute("count");
    if (count == null) {
    count = "1";
    } else {
    int temp = Integer.parseInt(count) + 1;
    session.setAttribute("count", Integer.valueOf(temp));
    request.getRequestDispatcher("/test").forward(request,response);
    }
    }
    谢谢大家咯..
    我同学帮我解决了..
      

  4.   

    session放这个是不可以的,你这里,实际上只是记录了用户访问某一个方法的次数
    或者说,用户在一个会话周期内,访问某一页面的次数而已