首页 > 代码库 > action访问servlet的API并且获取到MAP类型的application,session,request
action访问servlet的API并且获取到MAP类型的application,session,request
public class testAction3 extends ActionSupport { private Map<String,Object> request; private Map<String,Object> session; private Map<String,Object> application; /** * 构造函数,没有返回值 */ public testAction3(){ this.request=(Map) ActionContext.getContext().get("request"); this.session=ActionContext.getContext().getSession(); this.application=ActionContext.getContext().getApplication(); } @Override public String execute(){ System.out.println("开始。。。。"); this.request.put("reqAttr","reqDirect"); this.session.put("sessionAttr", "sessionDirect"); this.application.put("appAttr", "appDirect"); return SUCCESS; } }
<body> request:${reqAttr}<br> session:${sessionAttr}<br> application:${appAttr}<br> ------------------------------<br> request:${requestScope.reqAttr}<br> session:${sessionScope.sessionAttr}<br> application:${applicationScope.appAttr}<br> </body>
或者使用IoC方法:需要实现相应的接口
public class testAction3 extends ActionSupport implements RequestAware,SessionAware,ApplicationAware{ private Map<String,Object> request; private Map<String,Object> session; private Map<String,Object> application; @Override public void setApplication(Map<String, Object> application) { // TODO Auto-generated method stub this.application=application; } @Override public void setSession(Map<String, Object> session) { // TODO Auto-generated method stub this.session=session; } @Override public void setRequest(Map<String, Object> request) { // TODO Auto-generated method stub this.request=request; } @Override public String execute(){ System.out.println("开始。。。。"); this.request.put("reqAttr","reqDirect"); this.session.put("sessionAttr", "sessionDirect"); this.application.put("appAttr", "appDirect"); return SUCCESS; } }
action访问servlet的API并且获取到MAP类型的application,session,request
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。