1、客户端初始化一个指向请求
2、这个请求经过一系列的过滤器(Filter)
3、接着FilterDispatcher被调用,FilterDispatcher询问ActionMapper来决定这个请是否需要调用某个Action
4、如果ActionMapper决定需要调用某个Action,FilterDispatcher把请求的处理交给ActionProxy
5、ActionProxy通过ConfigurationManager询问框架的配置文件,找到需要调用的Action类 ,这里,我们一般是从struts.xml配置中读取。
6、ActionProxy创建一个ActionInvocation的实例。
7、ActionInvocation实例使用命名模式来调用,在调用Action的过程前后,涉及到相关拦截器(Intercepter)的调用。
8、一旦Action执行完毕,ActionInvocation负责根据struts.xml中的配置 找到对应的返回结果
当
Web容器收到请求(HttpServletReques
t)它将请求传递给一个标准的的过滤链包括(ActionContextCleanUp)过滤器。
经过Other filters(SiteMesh ,etc),需要调用
FilterDispatcher核心控制器
,然后它调用ActionMapper确定请求哪个Action,ActionMapper返回一个收集Action详细信息的ActionMaping对象。
FilterDispatcher将控制权委派给ActionProxy,ActionProxy调
用配置管理器(ConfigurationManager)
从
配置文件
中读取
配置信息
(struts.xml),然后创建ActionInvocation对象。
ActionInvocation在调用Action之前会依次的调用所用
配置拦截器或者拦截器栈
(Interceptor N)一旦执行结果返回结果字符串ActionInvocation负责查找结果字符串对应的(Result)然后执行这个Result Result会调用一些模版(JSP)来呈现页面。
拦截器(Interceptor N)会再被执行
(顺序和Action执行之前相反
)最后
响应(HttpServletResponse)被
返回
在web.xml中配置的那些过滤器和(核心控制器)(FilterDispatcher)。
Struts2
接收用户输入数据的三种方式
:
–
使用领域对象接收用户输入
–
使用
ModelDriven
action
–
使用
action
属性接收用户输入
Struts2
在
Action
中如何访问
request,session,application
(
即
ServletContext
)
对象
:
–
可以使用
struts2
中提供的
Map
对象来访问
HttpRequest,HttpSession
和
ServletContext
对象
–
也可以直接访问
Servlet
环境中的
HttpRequest,HttpSession
和
ServletContext
对象
//耦合的域对象
//ServletActionContext
HttpServletRequest request=ServletActionContext.getRequest();
HttpSession session=request.getSession();
ServletContext application= request.getServletContext();
String url= request.getContextPath();//文件上传和下载
//通过ActionContext来获取request,session,application
//解耦合的域对象
Map<String,Object> requestMap=(Map<String, Object>) ActionContext.getContext().get("request");
Map<String,Object> sessionMap= ActionContext.getContext().getSession();
Map<String,Object> applicationMap= ActionContext.getContext().getApplication();
OA ERP CRMpackagenamespase="/" 从根 “/abc” 例: /abc/loginuserextends="struts-default"name="tzhu" 唯一 : package 包继承包struts.xml: include 引入一个xml的配置文件 :分配配置文件的使用全局视图: action中共享视图<global-results><result name="index" type="dispatcher">/index.jsp</result><result name="error" type="dispatcher">/error.jsp</result><result name="success">/success.jsp</result><result name="main">/admin/main.html</result><result name="userlist">/admin/tab/userlist.jsp</result></global-results>action配置:1 视图化的配置2 创建类配置xml中的action 父类: ActionSupport 实现一个接口: Action常量: UTF-8<!-- 设置字符编码 --><constant name="struts.i18n.encoding" value="UTF-8"/><!-- 开发模式下使用,这样可以打印出更详细的错误信息 --><constant name="struts.devMode" value="true"/>参数:从表单到后台:内置参数封装的param拦截器使用视图:五个常量: SUCCESS ERROR INPUT NONE login引用时全大写的: SUCCESS ERROR INPUT (提交表单的视图:校验框架 )自己定义: 给上名字视图类型 ; 转发 重 定 向 重定向action<result name = "error" type = "dispatcher"> /error.jsp </result>action的提交方式有三种:1 !提交2 多配置文件 method="方法签名"3 通配符的方式: *user method= {1}