This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JSP and the fly likes JSP logout page shuld not go  back Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "JSP logout page shuld not go  back" Watch "JSP logout page shuld not go  back" New topic
Author

JSP logout page shuld not go back

Rupesh Sahay
Greenhorn

Joined: Aug 07, 2012
Posts: 3
Hi ,
I have made a website which has logout option.
I am using below code to logout the page.
now problem is whenever click on goback button on browser it taking me to the information page. which i dont want.
Request you to please give some suggestion to avoid the situation. Once i logout the information page should not come until i login again even i press on go back button.
THanks in advance

<%
//session.invalidate();

session.setAttribute("sessUserName",null);

%>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61317
    
  66

Are you properly setting no-cache headers so that the pages are not cached by the browser?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rupesh Sahay
Greenhorn

Joined: Aug 07, 2012
Posts: 3
NO,
I am new in JSP.
i am not aware about that.

below is my code

login page.
<html>
<body>
<form name="1" action="2.jsp">
<input type="text" name="value"/>
<input type=submit value="submit"/>
</form>
</body>
</html>

----------
2nd page

<%@page import="java.util.*" %>
<%@ page session="true"%>

<% String value=request.getParameter("value");
response.getWriter().println("Welcome "+ value);
%>

<%
String name=request.getParameter("value");
session.setAttribute("sessUserName",name);
%>
<html>
<body>

<h1>your are in page 2</h1>
<a href=3.jsp>log out</a>
</body>
</html>


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


<%
//session.invalidate();

session.setAttribute("sessUserName",null);

%>

You have logged out. Plese
<a href="1.html"><b>Login</b></a>
<%= session.getAttribute("sessUserName")%>
<%out.print("Hi this is new sessino :"+session.getAttribute("sessUserName"));%>


please advice.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61317
    
  66

OK, first to answer your question: see the JspFaq for JSP questions -- in particular, this entry.

Secondly, if you are new to JSP you need to know that you are writing it wrong! JSP scriptlets (the parts between <% and %>) are obsolete and have been discredited for over 10 years now! You are wirintg JSP as if it still 2001! See this JspFaq entry.

You should be learning to use JSP's JSTL and EL technologies; not obsolete Java scriptlets.
R. Jain
Ranch Hand

Joined: Aug 11, 2012
Posts: 375
    
    1

Rupesh Sahay wrote:Hi ,
I have made a website which has logout option.
I am using below code to logout the page.
now problem is whenever click on goback button on browser it taking me to the information page. which i dont want.
Request you to please give some suggestion to avoid the situation. Once i logout the information page should not come until i login again even i press on go back button.
THanks in advance

<%
//session.invalidate();

session.setAttribute("sessUserName",null);

%>


This is in fact a very general problem with JSP beginners.
I think this post will solve all your problems.. :thumbup:
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61317
    
  66

R. Jain wrote:I think this post will solve all your problems.. :thumbup:

Except that a lot of the advice given in that topic is very poor. Trying to disable the back button is a ridiculous and useless attempt to band-aid the real problem. And any JavaScript history hacks can be easily circumvented.
R. Jain
Ranch Hand

Joined: Aug 11, 2012
Posts: 375
    
    1

Bear Bibeault wrote:
R. Jain wrote:I think this post will solve all your problems.. :thumbup:

Except that a lot of the advice given in that topic is very poor. Trying to disable the back button is a ridiculous and useless attempt to band-aid the real problem. And any JavaScript history hacks can be easily circumvented.


Yeah, Actually I forgot to point out that. And yes, disabling the browsers back button is useless. I was just leading him towards the use of no-cache headers, to avoid browsers from caching the page..
But as I saw, just after I posted my reply, you have given an appropriate place for a nice explanation.. :D
Rupesh Sahay
Greenhorn

Joined: Aug 07, 2012
Posts: 3
Thanks for the help,
After adding the no-cache header its working,
Its still not working on the Google crome, but in IE its working fine.
Thanks a lot for your support.
 
GeeCON Prague 2014
 
subject: JSP logout page shuld not go back