File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Java » JSP
Bookmark "Log Out Problem" Watch "Log Out Problem" New topic
Author

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.*" %>

<%
session.invalidate();
session=request.getSession(true);
response.sendRedirect("login.htm");
%>
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41106
    
  45
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.


Ping & DNS - my free Android networking tools app
anuj patel
Greenhorn

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
Sheriff

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
Hi,
You can disable back button by javascript.......

"javascript:window.history.forward(-1);"
to write this code in body onLoad event

Regards,
Suresh Kumar.K
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60781
    
  65

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] [Bear's FrontMan] [About Bear] [Books by Bear]
anuj patel
Greenhorn

Joined: Jan 02, 2008
Posts: 10
Hi try this
logout.jsp

<html>
<%@ 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"/>

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

</head>
<body>

</body>
</html>
Olawale Olutola
Greenhorn

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.
 
Don't get me started about those stupid light bulbs.
 
subject: Log Out Problem
 
Similar Threads
Logout
Directing login errors to form-login-page -- spurious login error message
javascript called within JSP
problem using html:link
jsp