防止退出后返回上一页

时间:2011-02-17 16:40:12

标签: jsp servlets

的login.html

    <form method="get" action="NewServlet">
        name: <input type="text" name="user">
        <br>
        pass: <input type="password" name="password">
        <br>
        <input type="submit">
    </form>

 NewServlet


    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    String s = request.getParameter("user");
    String pass = request.getParameter("password");
    UserBean bean=new UserBean();
    bean.setLogin(request.getParameter("user"));
    bean.setPassword(request.getParameter("password"));
      if(bean.getLogin().equals("admin")&&bean.getPassword().equals("prerna"))

   {
       HttpSession session=request.getSession(true);

       request.setAttribute("user",bean);
       session.setAttribute("user",request);

       RequestDispatcher rd=request.getRequestDispatcher("/show.jsp");
       rd.forward(request,response);
    }
  else
 {
response.sendError(404, "invalid usename or password");
   // response.sendRedirect("http://www.google.com");
   out.print("<H1>ERROR</H1>");


 }

 loginout.jsp

<%

  session.invalidate();
  response.sendRedirect("login.jsp");

%>

当我点击后退按钮时,我显示了我不想要的上一页。 任何人都可以建议我解决这个问题

1 个答案:

答案 0 :(得分:0)