简体   繁体   English

在后退按钮上单击注销后重新加载jsp页面

[英]reload jsp page after logout on back button click

In every page of mine, there is a logout option. 在我的每一页中,都有一个注销选项。 When the user clicks this logout option, they get log out session.invalidate(); 当用户单击此注销选项时,他们将注销session.invalidate(); .When I press the back button, even if the session is invalidated, I get the previous page with all the contents in the input tag.How can I resolve this problem.I tried window.location.reload() ,and many other options, but it's not working in here.\\ My website is this. 当我按下后退按钮时,即使会话无效,我也会获得上一页包含输入标签中所有内容的页面。如何解决此问题。我尝试了window.location.reload()和许多其他选项,但无法在此处使用。\\ 我的网站是这个。 and credentials are. 和凭据。 test123@gmail.com and pass is Amal123 test123@gmail.com并通过是Amal123

Before all pages you want to open only when session is active you have to put a filter that checks for session before your pages get open. 仅在会话处于活动状态时,要打开所有页面之前,您必须放置一个过滤器,以在打开页面之前检查会话。

And on loguot you have to invalidate the current session. 在登录时,您必须使当前会话无效。

And then your will be able to press back button but can not perform any funtionality 然后您将可以按返回按钮,但不能执行任何功能

You can use a session attribute... for example when you log in, set a variable value to username eg: HTML 您可以使用会话属性...例如,当您登录时,将变量值设置为用户名,例如:HTML

<form name="login" action="/login.jsp" method="post" >
    <input type="text" name="username" >
    <input type="password" name="password" >
<input type="submit" >

JSP: JSP:

String userName=request.getParameter("username");
request.getSession().setAttribute("username",userName);

Now On every page,add this code 现在在每个页面上添加此代码

<% if(request.getSession().getAttribute("username")==null) response.sendRedirect("index.jsp");%>

Also, at the time of logout do not forget to remove the session attribute. 同样,在注销时不要忘记删除会话属性。

request.getSession().removeAttribute("username");

Try it and let me know. 试试看,让我知道。

you can copy and paste this code in every page of your site which clears the cached page. 您可以将此代码复制并粘贴到网站的每个页面中,以清除缓存的页面。

 <%
response.setHeader("Cache-Control","no-cache");
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragma","no-cache");
response.setDateHeader ("Expires", 0);

if(session.getAttribute("some_token")==null)
  response.sendRedirect("login/login.html");

%> 

In logout you must be invalidating session so when you click back it would check the some_token attribute value in session and if not there it will redirect you to login page . 在注销中,您必须使会话无效,因此,当您单击返回时,它将检查sessionsome_token属性值,如果不存在,则会将您重定向到login页面。 But remember after login you are setting some_token attribute in session. 但是请记住,登录后要在会话中设置some_token属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM