wood burning stoves 2.0
The moose likes JSP and the fly likes Log Out Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Log Out Problem" Watch "Log Out Problem" New topic

Log Out Problem

Subhradip Podder
Ranch Hand

Joined: Aug 27, 2007
Posts: 36
HI All,
i'm trying to build a web page which permits the user to login before accessing the contents of the site. the login works fine (i did it using jsp), but i am not able to logout properly, that is, when i click on a "logout" hyperlink, it sends me to the proper page, but when i do "back" on my explorer, it gives me the previous page again. so my logout is pointless.

can anyone tell me how to prevent this from happening please?i don't know if i should use jsp, javascript or html to do this.
i need this urgently for my project.
thanks for replying as possible

My Log Out Code:-

<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Make sure the cache headers are set not to cache: http://faq.javaranch.com/java/NoCacheHeaders

But ultimately, this is up to the browser. Some browsers do not access the server upon clicking the back button, but simply redisplay the cached page.
anuj patel

Joined: Jan 02, 2008
Posts: 10
use the javascript to disable the back button of the browser
Anirvan Majumdar
Ranch Hand

Joined: Feb 22, 2005
Posts: 261
Originally posted by anuj patel:
use the javascript to disable the back button of the browser

I don't think that has been accomplished effectively as yet. Like Ulf mentions, handling the Cache headers is one way to go about it [but whether that'll prevent the last screen from displaying depends on the browser]. Another thing you can try is associating an "onLoad" method with your page <body>, which will in turn make an AJAX call to determine whether the session is active. If not, then you can redirect the user to the logout/login screen using JavaScript.

Let me know if this helps you.
Subhradip Podder
Ranch Hand

Joined: Aug 27, 2007
Posts: 36
HI Arjun,

Kindly write me the logout code using java-script,because i'm not well known java script.

Please help me.
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Javascript is not going to help you here.
There is no way to disable the back button using JavaScript.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
K.Suresh Kumar
Ranch Hand

Joined: Nov 21, 2007
Posts: 41
You can disable back button by javascript.......

to write this code in body onLoad event

Suresh Kumar.K
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63873

Originally posted by K.Suresh Kumar:
You can disable back button by javascript
How atrocious. And no, this code does not disable the back button. It merely gives it non-standard and extremely annoying behavior.

It's a much better idea to write the web app correctly in the first place rather than relying upon hacks that merely serve to annoy your users.

[Asking smart questions] [About Bear] [Books by Bear]
anuj patel

Joined: Jan 02, 2008
Posts: 10
Hi try this

<%@ page session="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>

<c:redirect url="/jsp/index.jsp"/>

<META Http-Equiv="Cache-Control" Content="no-cache">
<META Http-Equiv="Pragma" Content="no-cache">
<META Http-Equiv="Expires" Content="0">


Olawale Olutola

Joined: Apr 04, 2008
Posts: 5
i think it should not be much of problem. since you have invalidated the session, the user will not be able be able to access anything on page again after using the back button.
I agree. Here's the link: http://aspose.com/file-tools
subject: Log Out Problem
jQuery in Action, 3rd edition