的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");
%>
当我点击后退按钮时,我显示了我不想要的上一页。 任何人都可以建议我解决这个问题
答案 0 :(得分:0)
尝试添加pragma no-cache标头:http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.32