Solved

jsp and session invalidate

Posted on 2002-07-09
8
1,428 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

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 This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.

758 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

19 Experts available now in Live!

Get 1:1 Help Now