开发者

prevent going back to previous page after logging out

login.html

    <form method="get" action="NewServlet">
        name: <input type="text" name="user">
        <br>
        pass: <input type="password" name="password">
        <br开发者_C百科>
        <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");

%>

when I click on back button my previous page gets displayed which i don't want. can anyone suggest me a solution for this problem


Try adding the pragma no-cache header: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.32

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜