Solved

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

Posted on 2004-09-07
14
190 Views
Last Modified: 2010-03-31
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
0
Comment
Question by:sdushyanth
  • 3
  • 3
  • 2
  • +2
14 Comments
 

Author Comment

by:sdushyanth
Comment Utility
please send me solution to this question,
thank u
dushyanth
0
 
LVL 9

Expert Comment

by:Nick_72
Comment Utility
Try moving these lines above the <html> tag

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

 
%>
0
 
LVL 12

Expert Comment

by:Giant2
Comment Utility
the browser back button is not governed by your code.
Yu could disable this button, so you don't care about this.
0
 
LVL 12

Expert Comment

by:Giant2
Comment Utility
0
 

Author Comment

by:sdushyanth
Comment Utility
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 ,
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:sdushyanth
Comment Utility
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

0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
Comment Utility
0
 
LVL 9

Expert Comment

by:Nick_72
Comment Utility
sdushyanth,

try using addHeader() instead of setHeader()
0
 
LVL 1

Expert Comment

by:jLasitha
Comment Utility
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
0
 
LVL 12

Expert Comment

by:Giant2
Comment Utility
I think a delete with point not refund because some solution were done, but sdushyanth not accept any of them(for now).
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
the code in the link I posted fixed the same problem in that question.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now