Access or add request/session/application
1. Use ActionContext
// Place it like this
Public String execute ()
{
ActionContext ctx = ActionContext. getContext ();
Ctx. getApplication (). put ("app", "lll ");
Ctx. getSession (). put ("ses", "session range ");
Ctx. put ("req", "request range ");
Return "success ";
}
// Retrieve
$ {ApplicationScope. app}
$ {SessionScope. ses}
$ {RequestScope. req}
2. obtain the corresponding object
2.1 get the result directly through the ServletActionContext class:
Public String rsa () throws Exception {
HttpServletRequest request = SerletActionContext. getRequest ();
Request. setAttribute ("req", "request range attribute ");
Request. getSession (). setAttribute ("res", "session attribute ");
}
2.2 implement the specified interface, which is injected by the struct2 framework during runtime
Public class HelloWorldAction implements ServletRequestAware, ServletResponseAware, ServletContextAware
{
Private HttpServletRequest request;
Public void setServletRequest (HttpServletRequest req ){
This. request = res;
}
}