File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes private variable holds value when returning to action Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "private variable holds value when returning to action" Watch "private variable holds value when returning to action" New topic
Author

private variable holds value when returning to action

brian welter
Greenhorn

Joined: Jun 17, 2011
Posts: 3
I've been every time I revisit this issue.


I have a base action support class that all my application actions extend....



I alter "stuck variable" in numerous actions that extends MyActionSupport, I set by calling it's setter.



Now everytime I returun to the DisorderAction, the value of stuckvariable is "wtf mate" before I even set it. Basically I need to clear the user session and clear a bunch of values across the entire app, but no matter what I do, it remains.

I've tried numerous ways to clear the session:
e.g. ((org.apache.struts2.dispatcher.SessionMap) ActionContext.getContext().getSession()).invalidate();

I must be missing something terribly obvious with the scope of that variable. Please help!
Jesus Mireles
Ranch Hand

Joined: Mar 10, 2010
Posts: 122

The scope is not session so the session.invalidate will not do anything.

Is this Struts1 or Struts2? In Struts1 you only get one instance of an action class. Struts2 creates an instance per request of an action.

-Jesus M.
brian welter
Greenhorn

Joined: Jun 17, 2011
Posts: 3
I'm using Struts2, 2.1.8 specifically.

Some other details on the project...

I'm also using Spring 2.5.6 for dependency injection ... so spring is set up as the default context loader.

Here's the web.xml


I'm also using Freemarker for the presentation layer although I don't think that could possibly cause this.
Jesus Mireles
Ranch Hand

Joined: Mar 10, 2010
Posts: 122

I don't know spring as well as I know struts.

What I can tell you is that stuts 2 does not behave this way out of the box. I would probably imagine that your spring configuration might be the culprit.

JM
brian welter
Greenhorn

Joined: Jun 17, 2011
Posts: 3
You were absolutely right...spring was the culprit...

I was referencing a spring bean for my actions so I could inject my manager classes easily. I simply needed to set the scope of the action beans to prototype and everything is working perfectly now.

Thanks for your time!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: private variable holds value when returning to action