struts的动态方法访问模式
<struts>
<constant name="struts.enable.DynamicmethodInvocation" value="true"></constant>
</struts>
耦合和解耦合的获取作用域方法:
①解耦合的方法 Map (不依赖servlet)
②耦合的方法 HttpServletRequest、HttpServletResponse、session、ServletContext…
①例1: private Map<String,Object> application;
public String text(){
application=(Map<String,Object>)ActionContext.getContext.get("application");
}
设置值:
application.put("list",list);
①例2:实现接口
implements RequestAware,SessionAware,ApplicationAware{
private Map<String,Object> request; //类初始化了,request中就有对象。
//提供get,set方法
public void getRequest(){
//..............................
}
}
②实现接口
implements ServletRequestAware,ServletReponseAware............{
private HttpServletRequest request;
private HttpServletResponse response;
private ServletContext application;
}
②通过ServletActionContext静态方法获取
HttpServletRequest request=ServletActionContext.getRequest();
HttpServletResponse response=ServletActionContext.getResponse();
ServletContext application=ServletActionContext.getServletContext();