Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding ActionContext's ContextMap

 
Gaurav Kushwaha
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have an application which will be used by multiple users. Currently, I am storing a object in session that will be used by multiple Actions Classes.
I want to avoid using session.
I tried using the ActionContext's getContextMap/parameters but it didn't help as I guess its clearing with every new request.

Please help !!
 
Samson Mlati
Ranch Hand
Posts: 41
Hibernate Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gaurav Kushwaha wrote:Hi,

I have an application which will be used by multiple users. Currently, I am storing a object in session that will be used by multiple Actions Classes.
I want to avoid using session.
I tried using the ActionContext's getContextMap/parameters but it didn't help as I guess its clearing with every new request.

Please help !!


Why don't you load it in a servlet?
 
Gaurav Kushwaha
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.
The field that I am setting in session is not available beforehand, it gets filled up by an intermediary action class.
So I can't have that in the servlet.
 
Tom Rispoli
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could put the value into a hidden field in the html you send to the user. Then retrieve it from the request the user submits to the subsequent actions.
 
Shashank Ag
Ranch Hand
Posts: 88
Java Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See in a basic servlet api there are 3 main scopes, request, session and application (ServletContext).
Struts "ActionContext" getContextMap/parameter gives a copy of context-params specified in web.xml.
These values are ment to be readonly once application is deployed, as per servlet api.

Hence, it did not worked out. And yes its a bug in Struts that ActionContext.getContextMap gives you a Map instance which is modifiable.
 
Shashank Ag
Ranch Hand
Posts: 88
Java Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hence, They way it can be done is via session. But otherways like threadlocale could be thought of based onwhat requirement you have.
However, threadlocale solution will still be depedent upon some session value only.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic