论坛首页 入门技术论坛

Struts2总结

浏览 1866 次
锁定老帖子 主题:Struts2总结
精华帖 (0) :: 良好帖 (0) :: 新手帖 (1) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-03-22  
Struts2使用OGNL进行类型转换。提供基本和常用对象的转换器。
Struts2使用“ValueStack”技术,使taglib能够访问值而不需要把你的页面(view)和对象绑定起来。
Struts2支持通过拦截器堆栈(Interceptor Stacks)为每一个Action创建不同的生命周期。


temp:#ActionContext储存了整个访问周期中的request,session,application
1、FilterDispatcher的处理流程
   1、处理HttpServletRequest,如果思上传的请求,对request进行包装
   2、查找该请求路径是否有对应的Action,有的话把该路径包装成一个ActionMapping对象
      #ActionMapping对象中含有name,method,namespace,params,result等属性(holds the action mapping information)
   3、交给Dispatcher类的serviceAction(request, response,servletContext,mapping)方法处理

2、Dispatcher类的处理过程
   1、分别实例化几个储存request,session,application的信息的Map对象

3、Struts2中的拦截器
   DispatcherFilter拦截器
   ActionAutowiringInterceptor拦截器
   ParametersInterceptor拦截器
   ServletConfigInterceptor拦截器

4、几个辅助接口
   SessionAware-通过Map来提供对所有session属性的访问
   ServletRequestAware-提供对HttpServletRequest对象的访问
   RequestAware-通过Map来提供对所有request属性的访问
   ApplicationAware-通过Map来提供对所有application属性的访问
   ServletResponseAware-提供对HttpServletREsponse对象的访问
   ParameterAware-通过Map来提供所有request String和表单数据的访问
   PrincipalAware-提供对PrincipleProxy对象的访问;该对象实现了HttpServletRequest对象的有关pringcile和role的方法,但是它提供了一个   Proxy,因此所有的实现都是独立于Action的。
   ServletContextAware-提供对ServletContext对象的访问

5、struts2的扩展自定义拦截器
   自定义拦截器实现Interceptor接口或者继承AbstractInterceptor 
   ActionInvocation对象可以用来访问运行时环境,以及Action本身;上下文(包括了Web应用的请求参数,session参数,用户Local等);Action   的执行结果;还有那些调用Action的方法并判断Action是否已被调用。

6、缩小Action的配置文件的牛X配置
   前提:struts.enable.SlashesInActionNames = true;
   URL模式:/{module}/{entity}/{action}.action
   配置文件:
   <action name="*/*/*" method="{3}" class="com.infoq.action.{1}.{2}action">
     <result name="view">/{1}/update{2}/jsp</result>
     <result name="list">/{1}/list{2}.jsp</result>
   </action>
   使用超强通配符
   发表时间:2010-02-03  
很简洁啊!
0 请登录后投票
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics