Solved

jsp and session invalidate

Posted on 2002-07-09
8
1,456 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

830 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