Solved

jsp and session invalidate

Posted on 2002-07-09
8
1,467 Views
Last Modified: 2008-01-09
What is the correct syntax for the below.  I am trying to end the session on a jsp page which consists of a form and when hit the reset button it will end the session.

<%
session.invalidate();
<a href="#" onClick="document.pensionBenefits.reset(); return false"><IMG src="images/butn-reset-e.gif" width="73" tabindex="28" height="18" border="0" alt="Reset" align="bottom" ></a>
%>
0
Comment
Question by:schroom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 5

Expert Comment

by:fontaine
ID: 7141240
The <a href ... > should not be part of your JSP block as far as it is not Java code. You should write:

<%
session.invalidate();
%>
<a href= ..... >

However, if you absolutely want to output the <a href=....> from your JSP block, you can do it the following way:

<%
session.invalidate();

out.println("<a href=\"#\" onClick=\"document.pensionBenefits.reset(); return false\"><IMG src=\"images/butn-reset-e.gif\" width=\"73\" tabindex=\"28\" height=\"18\" border=\"0\" alt=\"Reset\" align=\"bottom\" ></a>");
%>
0
 
LVL 19

Accepted Solution

by:
cheekycj earned 100 total points
ID: 7141471
that will not have the desired effect.

You need to have the reset button open a new window or submit to a page that will do the session.invalidate() call.

The way you have it currently coded will invalidate the session regardless of whether the reset button is clicked or not.

CJ
0
 

Expert Comment

by:sunilrangwani
ID: 7144542
hi

greetings
if you wish to invalidate the session, "session.invalidate()" is the correct syntax. But remember, if you refresh  the page this line will give an exception i.e.
java.lang.IllegalStateException : Session already invalidated....<wotever>

Hence you put it in try/catch as follows :
try
{
  session.invalidate()
}
catch(Exception e)
{
  // Ignore this exception- do nothing.
}


And if you still feel your session is not getting invalidated, clear the browser cache and temp. internet files.

Tell me if it worked for u
regards
Sunil
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:schroom
ID: 7145742
Well, it seemed to me with testing that the way I was able to get it to work was to actually go to another page. (reset.jsp)

<a href="reset.jsp"><img src="images/butn-reset-e.gif" alt="Reset"></a>

where on that page I have (which does work and didn't work without the clearing the cache stuff
<%
session.invalidate();
response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server

String refURL = request.getHeader("referer");
out.println (refURL);
if (refURL !=null)
if (refURL.endsWith("calculator-e.jsp") ) {  
%>
 <META HTTP-EQUIV="Refresh" CONTENT="3;URL=http://test/pbcdev/calculator-e.jsp">
                   
<%
 } else {
%>
<%--no additional table row required--%>

<META HTTP-EQUIV="Refresh" CONTENT="3;URL=http://test/pbcdev/calculator-e.jsp">

<% } %>    

only thing I need to change was the meta data, I don't want to use a absolute url
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7146388
>Well, it seemed to me with testing that the way I was able to get it to work was to actually go to another page. (reset.jsp)

That is what I meant by stating: "You need to have the reset button open a new window or submit to a page that will do the session.invalidate() call."

CJ
0
 
LVL 5

Expert Comment

by:vemul
ID: 7887948
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- PAQ'ed and points NOT refunded

Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

vemul
Cleanup Volunteer
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7891374
vemul:  I had suggested what the user ended up using in my first comment.  IMHO, the pts should be awarded to me.

CJ
0
 
LVL 1

Expert Comment

by:Computer101
ID: 7959664
Comment from expert accepted as answer

Computer101
E-E Admin
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question