I have a list that is accessible to all user of my application.I am currently adding it to session of a particular user.But i want it to be in application scope rather than session scope.Please help also provide reference/link to any example
Asked
Active
Viewed 7,210 times
3
-
If you are using Struts2, declare your static list in a class and access it through static reference: http://stackoverflow.com/questions/6906629/accessing-static-variable-using-ognl-in-struts2 – James Jithin Oct 08 '13 at 06:40
-
thank for reply is there another way something like aplication context? – satishkhowal Oct 08 '13 at 06:49
-
If you refer to a static item from a Class, it will be same throughout the application, right? – James Jithin Oct 08 '13 at 06:56
-
i know about static item i was asking about application context. – satishkhowal Oct 08 '13 at 08:56
2 Answers
4
In action you can use :
ServletActionContext.getContext().getApplication().put("myVar", myObj);
In order to set in a JSP, you can use the <s:set>
tag as :
<s:set name="myVar" scope="application" value="myObj"/>

coding_idiot
- 13,526
- 10
- 65
- 116
0
I am not sure how you want to use the list: you want to display that list to the screen or you just need it as configuration. To display it you could:
- create your list
statically
in your Action, then display it in the JSP - you could take the list
dynamically
from a database, then display it in the JSP
To use it as configuration: some data can be made available at application level at initialization, but those are configuration params. More info here:
Using the ServletContext
is the only way you can set parameters dynamically to the servlet from your code: servletContext.setAttribute()
. More info here:

Community
- 1
- 1

bogdan.herti
- 1,110
- 2
- 9
- 18