方法一:
在HelloWorldAction.java中的execute函数中添加如下代码:
ActionContext ctx = ActionContext.getContext();//往ServletContext里放入app
ctx.getApplication().put("app", "应用范围");//往session里放入ses
ctx.getSession().put("ses", "session范围");//往request里放入req
ctx.put("req", "request范围");
方法二:
在HelloWorldAction.java中添加一个新方法,添加如下代码:
public String rsa(){
HttpServletRequest request = ServletActionContext.getRequest();//获取request对象
ServletContext servletContext = ServletActionContext.getServletContext();//获取context对象
request.setAttribute("req", "请求范围范围");
request.getSession().setAttribute("ses", "会话范围");//获取session对象,并设置属性
servletContext.setAttribute("app", "应用范围");;
// HttpServletResponse response = ServletActionContext.getResponse();
return "success";
}
在对应的视图文件hello.jsp文件中加入如下显示代码:
<br>${applicationScore.app}
<br>${sessionScope.ses }
<br>${requestScope.req }