• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Back Button issue in browser after logout

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

My problem is when i m clicking logout button it will successfully goes on login page but when i click on back button it loads previous page which i don't want..please help me it's urgent..My lagout page is as follows..And i have tried all solutions available on net..


logout.jsp


<%--
Document : logout
Created on : 1 Nov, 2013, 6:43:53 PM
Author : ASUS
--%>

<%@page contentType="text/html" pageEncoding="UTF-8" session="false" autoFlush="true" %>
<!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=UTF-8">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
<title>Logout</title>
<script language="javascript">
window.history.forward(1);
browser.cache.offline.enable = false;
function noBack() { window.history.forward(1);

}
//***Get what is above onto one line***

self.close()
//function disableBackButton()
//{
//window.history.forward(1);
//}
//setTimeout("disableBackButton()", 0);
</script>

</head>
<body onload="noBack()" >
<h1>

<%

request.getSession().invalidate();

//response.setHeader("Cache-Control","no-store"); //HTTP 1.1
//response.setHeader("Cache-Control","no-cache");
//response.setHeader("Pragma","no-cache"); //HTTP 1.0
//response.setDateHeader ("Expires", 0); //prevents caching at the proxy server

response.sendRedirect("login.jsp");


%>
</h1>
</body>
</html>
 
Bartender
Posts: 2265
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all please put your code inside code tags. Now coming to your problem, I guess you must have stored the user credentials in scoped variable. When the logout event occurs removed the values from these scoped variables, and in this page check the value of those scoped variables, if that's null redirect to login page.
 
Ranch Hand
Posts: 228
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you change this code to and then post what is happening?

Also have a look at Servlet Faq
 
zalak thakkar
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your reply...

But i got the solution of it using javascript..But there is a problem in session management..can you help me on that?..every time i try to get the session attribute values and i got null.
And yes i check for new session using isNew() method but it doesn't affect my code..what should i do?


login.jsp

 
zalak thakkar
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My welcome page which retrieve attributes is as follows..

welcome.jsp

 
Ishan Pandya
Ranch Hand
Posts: 228
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you checked what output does gives on console from your welcome.jsp?? It must b null.

It is not recommended that you should use Scriplets and java code in your JSP. Use Servlets to set session values and the forward it to JSP.
 
zalak thakkar
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But Can't i use session tracking or say management in jsp??..And yes i'll try using servlet but if i'll have any problem i'll be back..Thanks
 
zalak thakkar
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok i have tried session in servlet

here is my validate.java code..





And My login and welcome pages are same as i posted before.. The only change is..




Is it Ok?..But i still get null instead of value...!!
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you think a line like "alert(window.location = "validate")" accomplishes? Where did you get the idea that it might do something useful?
 
zalak thakkar
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the code "alert(window.location = "validate")" is working...I have checked it..The problem is that i could not retrieve attribute which i set using session.setAttribute() method and it returns me null..
 
Ishan Pandya
Ranch Hand
Posts: 228
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what do you think will this code:



execute after an "else" condition??

And you are setting a session attribute named "user" in your servlet and in welcome.jsp page you are getting it back by "UserName"??
 
Swastik Dey
Bartender
Posts: 2265
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


What are you trying to achieve with the above code? I guess the submit request goes to validate servlet not welcome.jsp. So what do you expect request.getParameter("login") to return in this page? Moreover you are already setting username in session in validate servlet. So your jsp should just retrieve the value and print i.e.

 
Maybe he went home and went to bed. And took this tiny ad with him:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic