This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: private variable holds value when returning to action
 
Similar Threads
returning user defined strings in Struts 2 action classes
Struts - basic form submission -- variable changed values not holding
Show the value in select tag
Pass a variable from JSP to Servlet Action
Struts 2 + Hibernate JUnit test