1.通过ActionContext的类访问
ActionContext context = ActionContext.getContext();
context.put("requestName","requestNameMike");
context.getSession().put("sessionName", "sessionName");
context.getApplication().put("applictionName", "applictionName");
JSP中接收
request接收:${requestScope.requestName}<br>
session接收:${sessionScope.sessionName}<br/>
application接收:${applicationScope.applictionName}<br/>
2.通过特定xxxAware接口访问
实现接口 ServletRequestAware
public class TestParater extends ActionSupport implements ServletRequestAware
private HttpServletRequest request;
public void setServletRequest(HttpServletRequest request) {
// TODO Auto-generated method stub
this.request = request;
}
request.setAttribute("ServletRequestAware", "ServletRequestAware");
jsp页面获取
String servletRequestAware = (String)request.getAttribute("ServletRequestAware");
3.通过servleActionContext
HttpServletRequest request = ServletActionContext.getRequest();
request.setAttribute("servletActionContext", "ServletActionContext");
jsp页面获取
String servletRequestAware = (String)request.getAttribute("servletActionContext");