第八记:域属性的添加和访问
(1)、设置访问属性
1-1:通过ActionContext设置访问属性
public String execute(){
ActionContext act=ActionContext.getContext();
act.getApplication().put("application","this is application scope");
act.getSession().put("session","this is session scope");
act.put("request","this is request scope");
return "SUCCESS";
}
1-2:通过ServletActonContext设置属性
原理:获取到HttpServletRequest对象,利用setAtrribute()来实现。
HttpServletRequest request=ServletActionContext.getRequest();
ServletContext servletContext=ServletActionContext.getServletContext();
servletContext.setAttributet("application","this is application scope");
request.getSession().setAttributet("session","this is session scope");
request.setAttributet("request","this is request scope");
return "SUCCESS";
}
(2)、访问设置的属性
在success.jsp页面中用EL表达式获取值:
${applicationScope.application}<br/>
${sessionScope.session}</br>
${requestScope.request}<br/>