Solved

jsp and session invalidate

Posted on 2002-07-09
8
1,440 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
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
split53 challenge 7 96
Weekend adv creator 3 38
Unhandled exception type Exception 18 31
mysql jsp example issue 32 37
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…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

777 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