Struts2之初探Ioc模式

来源:互联网 发布:为什么4g网络突然很慢 编辑:程序博客网 时间:2024/06/04 19:41

声明:这是转帖的

版本 Struts2.1.2

lib列表

1 非IoC方式

com.opensymphony.xwork2.ActionContext,我们可以通过它的静态方法getContext()获取当前Action的上下文对象。

 

 

2 IoC方式

 

3 程序代码

 

IoC方式:

 

 

servlet.jsp

 

struts.xml

 

运行:

 

【综述】

例:

  ActionContext.getContext().getSession().put("msg", "Hello World from NoIoc Session!");
  HttpServletRequest request = ServletActionContext.getRequest();
  HttpServletResponse response = ServletActionContext.getResponse();
  HttpSession session = request.getSession();