訪問或添加request/session/application
1 通過ActionContext
//這樣放置
public String execute()
{
ActionContext ctx = ActionContext.getContext();
ctx.getApplication().put("app","lll");
ctx.getSession().put("ses","session范圍");
ctx.put("req", "request范圍");
return "success";
}
//這樣取出
${applicationScope.app}
${sessionScope.ses}
${requestScope.req}
2 獲取相應對象
2.1 通過ServletActionContext類直接獲取:
public String rsa() throws Exception{
HttpServletRequest request = SerletActionContext.getRequest();
request.setAttribute("req","請求范圍屬性");
request.getSession().setAttribute("res","會話屬性");
}
2.2實現指定接口,由struct2框架運行時注入
public class HelloWorldAction implements ServletRequestAware,ServletResponseAware,ServletContextAware
{
private HttpServletRequest request;
public void setServletRequest(HttpServletRequest req){
this.request = res;
}
}