aspose file tools*
The moose likes Servlets and the fly likes session.invalidate() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "session.invalidate()" Watch "session.invalidate()" New topic
Author

session.invalidate()

Ravissant Markandey
Ranch Hand

Joined: Oct 24, 2007
Posts: 41
Hi Everyone,
Is it possible to retrieve a variable's value after the session has been invalidated? To give you a better idea of the situation, im using a filter to invalidate the session for a certain case, all's going just fine, now i just have to show a different error message after session invalidation. The earlier message was set simply on the basis of the ActionForward(Im using struts) which in turn got set to "failure"(user-defined) in the action class on session invalidation, thus mapping it to a standard jsp.
What i intend doing is matching a variable's value and displaying the desired result, using conditional statements in the same jsp.
But then coming to the main question, what kind of variable will hold a value even after session invalidation?
Please Help.

Regards,
Ravissant Markenday
Vijay Jeyam
Greenhorn

Joined: Nov 12, 2008
Posts: 15
Well in this case you may try using a ThreadLocal to store the value you require and read that.

The code could look some thing like this ....

public class SomeContext {
public static ThreadLocal<SomeContext> local = new ThreadLocal<SomeContext>();

private SomeObject something;

public static SomeContext getContext(){
SomeContext context = ( SomeContext) local.get();
if(context == null) {
local.set(new SomeContext());
}
return local.get();
}

public SomeObject getSomeObject() {
return something;
}

public void setSomeObject(SomeObject something) {
this.something = something;
}
}


Never Never Never Give Up...!!!
rakesh sugirtharaj
Ranch Hand

Joined: Dec 16, 2007
Posts: 151
Why not use the application context object?


Cheers!
RSR
Vijay Jeyam
Greenhorn

Joined: Nov 12, 2008
Posts: 15
We can use the application context provided we have to show the message to every one based on some condition. As this is very particular for the user whose session is invalidated I suggested Thread local....
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I would avoid using thread local in web applications.
Threads are something that's managed by the container.

Are you invalidating the session and showing the message in the same request?
If so, why not bind the message to request scope?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ravissant Markandey
Ranch Hand

Joined: Oct 24, 2007
Posts: 41
Thanks You for your replies Vijay, Rakesh And Ben. Ben as for your query, yes the message shows in the same request in which the session is invalidated. But then how do i bind the message/variable to request scope ?..do you mean using request.getParameter()?..if yes then that value wont persist if the user retries the same operation will it(or in other words, resubmits the request after the session has been invalidated)?
Thanks in advance, Ravissant Markenday
[ November 12, 2008: Message edited by: Ravissant Markandey ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

No, not request.getParameter (that is for HTML form fields and querystring parameters).

Use request.setAttribute and request.getAttribute as you would with session attributes.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: session.invalidate()