This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

session.invalidate()

 
Ravissant Markandey
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;
}
}
 
rakesh sugirtharaj
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not use the application context object?
 
Vijay Jeyam
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ravissant Markandey
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic