JavaScud | Forum | JIRA | Blog |
  Dashboard > WebWork2文档中文化计划 > ... > Cookbook > Accessing application, session, request objects
  WebWork2文档中文化计划 Log In View a printable version of the current page.  
  Accessing application, session, request objects
Added by scud, last edited by scud on May 19, 2006  (view change)
Labels: 
(None)

Webwork provides several access helpers to access Session, Application, Request scopes.
Web agnostic (independent of the servlet API) with calls:

Map session = (Map) ActionContext.getContext().get("session");
session.put("myId",myProp);

The following gives you the same thing as above:

ServletActionContext.getRequest().getSession()

Note: Be sure not to use ActionContext.getContext() in the constructor of your action since the values may not be set up already (returning null for getSession()).
Note also: ActionContext.getContext().get("session") is the same as
ActionContext.getContext().getSession() with a cast to Map.

If you really need to get access to the HttpSession, use the ServletConfigInterceptor (see Interceptors).

In your views, you can access with your jsps as such

<ww: property value="#session.myId" />

<ww: property value="#request.myId" />

All the servlet scopes can be accessed like above.

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 dosen't exist, it will search request,session,application maps respectively.

Site running on a free Atlassian Confluence Open Source Project License granted to WebWork China. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.3 Build:#808 May 29, 2007) - Bug/feature request - Contact Administrators