Webwork The framework provides several access helpers to access Session, Application, Request scopes.
Web agnostic (independent of the servlet API) with calls:a single line of code.
Code Block | ||
---|---|---|
| ||
Map session = (Map) ActionContext.getContext().get("session"); session.put("myId",myProp); |
The following gives you the same thing as above:
Code Block | ||
---|---|---|
| ||
ServletActionContext.getRequest().getSession() |
...
Warning |
---|
Do not use |
...
Action class. The values may not be set up |
...
, and the call may return null for |
...
|
...
|
...
). |
...
If you really need to must have get access to the HttpSession, use the ServletConfigInterceptor (see Interceptors).
In your views, you can access with your jsps as suchJavaServer Pages with calls to the implicit properties session
and request
.
Code Block | ||
---|---|---|
| ||
<saf | ||
Code Block | ||
<ww: property value="#session.myId" /> <ww<saf: property value="#request.myId" /> |
All the servlet scopes can be accessed like abovevia the ActionContext.
Code Block | ||
---|---|---|
| ||
Map request = (Map) ActionContext.getContext().get("request"); request.put("myId",myProp); Map application = (Map) ActionContext.getContext().get("application"); application.put("myId",myProp); Map session = (Map) ActionContext.getContext().get("session"); session.put("myId", myProp); Map attr = (Map) ActionContext.getContext().get("attr"); attr.put("myId",myProp); |
The 'attr
' map will search the javax.servlet.jsp.PageContext
for the specified key. If the PageContext dosendoean't exist, it will search request}, {{session
, and application
maps respectively.