• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Log Out Problem

 
Subhradip Podder
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use the javascript to disable the back button of the browser
 
Anirvan Majumdar
Ranch Hand
Posts: 261
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Javascript is not going to help you here.
There is no way to disable the back button using JavaScript.
 
K.Suresh Kumar
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64205
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
anuj patel
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic