Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

session invalidate Pro

Status
Not open for further replies.

Khanjan

Programmer
Feb 24, 2004
41
NL
I have a JSP application which uses Session to store session values. I am having problem
invalidating the session. After logout i am able to access the application by clicking the browsers
back button and refreshing the page.

I use this code in Logout.jsp

<%if(session!=null)
{

session.invalidate();
}
%>response.sendRedirect(loginpage.html)


Can anybody explain what's wrong here?
 
Hi,

Isnt there any other way than using saveToken() and struts..?

 
If not using Struts, you can apply the same token idea. Use session ID as token and put that as a hidden field in the login form page. In the login process, if the token value is not the same as current session ID, then it is not a valid login.

In your logout page, you put
Code:
<%@ page session="false"%>

In your login page, within the login form:
Code:
<form ....>
<input type="hidden" name="sessionId" value="<%= session.getId() %>"/>

...

</form>
Then in the JSP or serlvet that process login:
Code:
<%
    String loginPageSessionId = request.getParameter("sessionId");

    if (loginPageSessionId==null 
        || !loginPageSessionId.equals(session.getId())) {
        // this is a login page refresh after logout
        response.sendRedirect("login.jsp");
        return;
    }
%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top