它不与此Prevent user from seeing previously visited secured page after logout重复。我研究过它以找出一些有用的东西。但这与我的问题无关。如果我在浏览器上禁用java脚本,这个重复的票证解决方案对我来说根本不起作用。请建议我,以便我可以进行正确的注销会议。 我尝试了很多注销代码,但没有任何工作在注销会话上。当我点击回来时,它将是正常的会话。 我的示例代码是,
"菜单中的退出链接:"
<a href="LogOut.do"><i class="fa fa-sign-out"></i><b> Logout</b></a>
&#34;退出Servlet代码&#34;:
public class LogOutServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setHeader("Cache-Control","no-cache"); //Forces caches to obtain a new copy of the page from the origin server
response.setHeader("Cache-Control","no-store"); //Directs caches not to store the page under any circumstance
response.setDateHeader("Expires", 0); //Causes the proxy cache to see the page as "stale"
response.setHeader("Pragma","no-cache"); //HTTP 1.0 backward compatibility
HttpSession session=request.getSession();
String userName = (String) session.getAttribute("customerDetails");
if (null == userName) {
request.setAttribute("Error", "Session has ended. Please login.");
RequestDispatcher rd = request.getRequestDispatcher("logout.jsp");
rd.forward(request, response);
}
}
}
&#34; logout.jsp&#34;
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
<title>Logout</title>
</head>
<body>
<% session.invalidate(); %>
<p>You have been successfully logout</p>
</body>
</html>
我尝试过许多不同的代码。但是当我点击浏览器的后退按钮时,它仍然正常显示主页。请帮助找到退出的最佳代码。