Solved

jsp and session invalidate

Posted on 2002-07-09
8
1,431 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groovy example issue 10 90
create a gui in perl 3 72
Eclipse IDE - Cannot copy/paste from console output 8 136
Java JRE greater than 1.6 5 51
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now