package com.lsp.lookweb; import java.util.Map; import org.apache.struts2.interceptor.ApplicationAware; import org.apache.struts2.interceptor.RequestAware; import org.apache.struts2.interceptor.SessionAware; import com.opensymphony.xwork2.ActionSupport; /** *Ioc(控制反转)--推荐使用 * 让Action类实现RequestAware、SessionAware、ApplicationAware接口, * 然后重写他们的set方法(setRequest、setSession、setApplication), * 通过依赖注入、控制反转(原来自己控制,现在由别人来控制值。 */ public class LookAction2 extends ActionSupport implements RequestAware, SessionAware, ApplicationAware { private Map<String, Object> session; private Map<String, Object> request; private Map<String, Object> application; public String LookAction2_() { request.put("r1", "r11"); session.put("s1", "s11"); application.put("a1", "a11"); request.put("r2", "r22"); return "LookAction2"; } @Override public void setRequest(Map<String, Object> req) { // TODO Auto-generated method stub this.request = req; } @Override public void setSession(Map<String, Object> sess) { // TODO Auto-generated method stub this.session = sess; } @Override public void setApplication(Map<String, Object> app) { this.application = app; } }