Link to home
Start Free TrialLog in
Avatar of sdushyanth
sdushyanth

asked on

Problem while logging out,removing the session variable but while navigating through back button previously viewed pages are showing up

Hai ya,

Probem: LOGOUT NOT WORKING PROPERLY,showing all previously viewed jsps.(pages)

I am designing a java web application ,using jsp,servlets and beans using model 2 architecture..
While trying to logout in web application ,it is going to login page, but we while navigating through back button, previously viewed pages are showing up, I have used removeAttribute method ,it is working fine,session variable is getting removed, But again while navigating through back button all the viewed pages are showing up. I dont know why they are not getting updated,i have written code the emptying the cache,can u please help me out in this.

here is my code in Logout.jsp..

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<html>
<head><title>JSP Page</title></head>
<script>
if(window.history.forward(1) != null)
                 window.history
.forward(1);
</script>
<body>
<% String re =(String)session.getAttribute("user");%>
<%
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragma","no-cache");
response.setDateHeader ("Expires", 0);

 
%>
before<%=re%>
<%
session.removeAttribute("user");
%>


<% String re1 =(String)session.getAttribute("user");%>
<%
 session.invalidate();
 


String url = response.encodeURL("LoginScreen.jsp");
response.sendRedirect(url);
%>
</from>
</body>
</html>

waiting for ur reply
dushyanth
Avatar of sdushyanth
sdushyanth

ASKER

please send me solution to this question,
thank u
dushyanth
Try moving these lines above the <html> tag

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

 
%>
the browser back button is not governed by your code.
Yu could disable this button, so you don't care about this.
I dont want to disable the browser 's back button,
and

I have tried  these lines above the <html> tag

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

 
%>

but still it is not working ,
Hai ya,

Probem: LOGOUT NOT WORKING PROPERLY,showing all previously viewed jsps.(pages)

I am designing a java web application ,using jsp,servlets and beans using model 2 architecture..
While trying to logout in web application ,it is going to login page, but we while navigating through back button, previously viewed pages are showing up, I have used removeAttribute method ,it is working fine,session variable is getting removed, But again while navigating through back button all the viewed pages are showing up. I dont know why they are not getting updated,i have written code the emptying the cache,can u please help me out in this.

here is my code in Logout.jsp..

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<html>
<head><title>JSP Page</title></head>
<script>
if(window.history.forward(1) != null)
                 window.history
.forward(1);
</script>
<body>
<% String re =(String)session.getAttribute("user");%>
<%
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragma","no-cache");
response.setDateHeader ("Expires", 0);

 
%>
before<%=re%>
<%
session.removeAttribute("user");
%>


<% String re1 =(String)session.getAttribute("user");%>
<%
 session.invalidate();
 


String url = response.encodeURL("LoginScreen.jsp");
response.sendRedirect(url);
%>
</from>
</body>
</html>

waiting for ur reply
dushyanth

ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sdushyanth,

try using addHeader() instead of setHeader()
Check the session in all pages.if the seesion null redirect it to tha loggin page
<% if( session.getAttributr("user") == null ){
      response.senRedirect("LoginScreen.jsp");
}
%>
Put this in all pages as a header
I think a delete with point not refund because some solution were done, but sdushyanth not accept any of them(for now).
the code in the link I posted fixed the same problem in that question.