• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

private variable holds value when returning to action

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 122
Mac IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 122
Mac IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Opportunity is missed by most people because it is dressed in overalls and looks like work - Edison. Tiny ad:
Enterprise-grade Excel API for Java
https://products.aspose.com/cells/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!