Solved

javascript reset and jsp session.invalidate

Posted on 2002-07-09
6
2,869 Views
Last Modified: 2007-12-19
THis is a javascripte and JSP question.
I am not sure of the syntax for ending the session on a JSP page, that is form.

That is instead of using a straight reset button, and clearing the form fields, I am trying to end the session using a reset button>

<%
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
6 Comments
 
LVL 33

Accepted Solution

by:
knightEknight earned 100 total points
ID: 7140945
you are trying to execute server functionality on the browser, which you cannot do.  You will have to do something like this:


<a href="endMySession.jsp" ><IMG src="images/butn-reset-e.gif" width="73" tabindex="28" height="18" border="0" alt="Reset" align="bottom" ></a>

and the content of endMySession.jsp would be ...

<%
   session.invalidate();

   // here put code to redirect somewhere
%>
0
 

Author Comment

by:schroom
ID: 7140964
Thanks knightEknight ,
I will try what you have posted and get back to you soon.
Thanks
0
 

Author Comment

by:schroom
ID: 7141015
I tried your suggestion, and it didn't seem to work. The reset button is clicked and the go to the endMySession.jsp, which has the
<%
                     session.invalidate();

                     // I just refreshed the page, but he session is still there.
                   %>

<a href="endMySession.jsp" ><IMG src="images/butn-reset-e.gif" width="73" tabindex="28"  height="18" border="0" alt="Reset" align="bottom" ></a>

Is there a way to clear the session without leaving the page, as they will will what to refill the form after resetting it.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Expert Comment

by:steve-e-b
ID: 7141048
Try targetting the endMySession.jsp into a hidden frame or sending it to a popup window that displays a confirmation message.

Steve
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 7141052
Perhaps you can put some conditional logic at the top of the page--something like:

if request.form("Reset") = "Reset" then
   session.invalidate
end if

That way, when the user clicks on the reset button, it returns him/her to the same page with the form with a terminated session.

Fritz the Blank
0
 

Author Comment

by:schroom
ID: 7141098
Thanks everyone for your help.
using:

 <a href="endMySession.jsp" ...
where I have the below (added the response stuff, it has cleared the session.
I can then use the referrer to get back to my form.
<%
     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
%>
and going to <a href="endMySession.jsp"
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

840 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