Struts2

用户请求在Struts2框架中的处理过程

  1. 客户端初始化一个指向Servlet容器(例如Tomcat)的请求。
  2. Container通过web.xml映射请求,并获得控制器(Controller)的名字。
  3. Container通过web.xml映射请求,并获得控制器(Controller)的名字。容器(Container)调用控制器(StrutsPrepareAndExecuteFilter或FilterDispatcher)。在Struts2.1以前调用FilterDispatcher,Struts2.1以后调用StrutsPrepareAndExecuteFilter
  4. 控制器(Controller)通过ActionMapper获得Action的信息。
  5. 控制器(Controller)调用ActionProxy。
  6. ActionProxy读取struts.xml文件获取action和interceptor stack的信息。
  7. ActionProxy把request请求传递给ActionInvocation。
  8. ActionInvocation依次调用action和interceptor。
  9. 根据action的配置信息,产生result.
  10. 产生一个HttpServletResponse响应
  11. 产生的响应行为发送给客服端。
Struts2_第1张图片
Struts请求响应流程
Struts2_第2张图片
Struts2

注意

  • web.xml文件。在Struts 2中,Struts框架是通过Filter启动的,他在web.xml中的配置如下:
 
 
     struts2 
      org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter  
        //配置文件struts.xml默认在src目录下,若更改则可加此段内容更改
        config   
        ../conf/struts.xml   
      

 
     struts2 
     /* 

在StrutsPrepareAndExecuteFilter的init()方法中将会读取类路径下默认的配置文件struts.xml完成初始化操作。
struts 2 读取到 struts.xml的内容后,以javabean形式存放在内存中,以后Struts 2对用户的每一次请求处理将使用内存中的数据。

  • ActionSupport 类。Action 继承了 ActionSupport 类 ,而该类实现了 Action 、Validateable 、 ValidationAware 、TextProvider、LocaleProvider、Serializable 接口。在Validateable 接口定义了一个 validate() 方法 , 在用户自定义 Action 类中重写该方法就可以实现 验证功能。

参考文章:
http://www.cnblogs.com/jbelial/archive/2012/05/10/2486886.html
http://blog.csdn.net/wuwenxiang91322/article/details/11070513
http://www.2cto.com/kf/201601/488282.html
http://huaxia524151.iteye.com/blog/1430148 代码配置

你可能感兴趣的:(Struts2)