`
uxr76uxr
  • 浏览: 13567 次
最近访客 更多访客>>
社区版块
存档分类
最新评论

struts2 处理请求流程分析(结合源码)1- 孤星随缘ツ http://t.sina.com.cn/samzhxing-iteye技术网站

 
阅读更多

struts2 处理请求流程分析(结合源码)1- 孤星随缘ツ http://t.sina.com.cn/samzhxing-iteye技术网站
2011年08月01日
  struts2 源码版本2.0.11.1
  本文是综合网上部分人的分析成果,然后再自己结合源码进行的,分析中如有错误,请指正。
  从struts2 中的web.xml的启动配置可以看出,首先分析的是FilterDispatcher 这个过滤器类。
  1、过滤器的初始化方法 void init(FilterConfig filterConfig)  //初始化方法 public void init(FilterConfig filterConfig) throws ServletException { this.filterConfig = filterConfig; //获得默认的参数,创建dispathcher 对象 dispatcher = createDispatcher(filterConfig); dispatcher.init(); String param = filterConfig.getInitParameter("packages"); String packages = "org.apache.struts2.static template org.apache.struts2.interceptor.debugging"; if (param != null) { packages = param + " " + packages; } this.pathPrefixes = parse(packages); } 
  1.1、createDispatcher(filterConfig);方法,该方法的目的是创建Dispathcher 对象  protected Dispatcher createDispatcher(FilterConfig filterConfig) { //读取相应过滤器的web.xml 配置 Map params = new HashMap(); for (Enumeration e = filterConfig.getInitParameterNames(); e.hasMoreElements(); ) { String name = (String) e.nextElement(); String value = filterConfig.getInitParameter(name); params.put(name, value); } //可以看出Dispatcher 类包装了ServletContext 和过滤器的web.xml 配置 return new Dispatcher(filterConfig.getServletContext(), params); } 
  1.2、dispatcher.init();方法,该方法对dispatcher进行了一系列的初始化工作,这个工作很重要也有点复杂,具体每个初始化的工作的流程怎样,待有空闲的时候再继续分析,网上也有人已经分析过了,如果有兴趣可参照:http://zddava.iteye.com/blog/211795 public void init() { if (configurationManager == null) { configurationManager = new ConfigurationManager(BeanSelectionProvider.DEFAULT _BEAN_NAME); } //读取properties信息,默认的default.properties init_DefaultProperties(); // [1] //读取xml配置文件,默认的struts-default.xml,struts-plugin.xml,struts.xml init_TraditionalXmlConfigurations(); // [2] //读取用户自定义的struts.properties init_LegacyStrutsProperties(); // [3] //读取FilterDispatcher的配置中所定义的actionPackages属性,传说中的Struts 2 零配置所谓的零配置 init_ZeroConfiguration(); // [4] //自定义的configProviders init_CustomConfigurationProviders(); // [5] //该功能全面被注释 init_MethodConfigurationProvider(); //载入FilterDispatcher传进来的initParams init_FilterInitParameters() ; // [6] //将配置文件中的bean与具体的类映射 init_AliasStandardObjects() ; // [7] //构建一个用于依赖注射的Container对象 //在这里面会循环调用上面七个ConfigurationProvider的register方法 //其中的重点就是DefaultConfiguration的#reload()方法 Container container = init_PreloadConfiguration(); init_CheckConfigurationReloading(container); init_CheckWebLogicWorkaround(container); }
  1.3、String param = filterConfig.getInitParameter("packages"); 以下的代码。这个步骤载入了packages标签下定义的静态资源。 读取web.xml中 的下面的配置路径还有org.apache.struts2.static,template,org.apache.struts2.interceptor.debugging这三个包空间下边的资源也会作为静态资源载入。   struts2  org.apache.struts2.dispatcher.FilterDispatcher   packages cn.static.resource  
  1.4、this.pathPrefixes = parse(packages);这个步骤是对packages 进行解析的。  protected String[] parse(String packages) { if (packages == null) { return null; } List pathPrefixes = new ArrayList(); StringTokenizer st = new StringTokenizer(packages, ", \n\t"); while (st.hasMoreTokens()) { String pathPrefix = st.nextToken().replace('.', '/'); if (!pathPrefix.endsWith("/")) { pathPrefix += "/"; } pathPrefixes.add(pathPrefix); } return pathPrefixes.toArray(new String[pathPrefixes.size()]); }
  
  
分享到:
评论

相关推荐

    Struts2漏洞检查工具2019版 V2.3.exe

    Struts2漏洞检查工具2019版 警告: 本工具为漏洞自查工具,请勿非法攻击他人网站! ==漏洞编号==============影响版本=========================官方公告==========================================影响范围====...

    struts-2.5.13-docs

    Apache Struts Copyright 2000-2011 The Apache Software Foundation This product includes software developed by The Apache Software Foundation (http://www.apache.org/). Dojo (http://dojotoolkit.org/). ...

    Struts2.rar

    S2-048 CVE-2017-9791 Struts 2.3.X http://127.0.0.1:8090/struts2-showcase/integration/saveGangster.action 影响范围非常小 S2-046 CVE-2017-5638 Struts 2.3.5-2.3.31,Struts 2.5-2.5.10 ...

    struts-2.1.8.1-src.zip

    Apache Struts Copyright 2000-2007 The Apache Software Foundation This product includes software developed by The Apache Software Foundation (http://www.apache.org/). Dojo (http://dojotoolkit.org/). ...

    struts2-core-2.3.15.3.jar

    Apache Struts Copyright 2000-2011 The Apache Software Foundation This product includes software developed by The Apache Software Foundation (http://www.apache.org/). Dojo (http://dojotoolkit.org/). ...

    struts-2.3.15.3-apps.zip

    Apache Struts Copyright 2000-2011 The Apache Software Foundation This product includes software developed by The Apache Software Foundation (http://www.apache.org/). Dojo (http://dojotoolkit.org/). ...

    Struts2漏洞检查工具2018版.exe

    增加S2-057 Struts 2.3 to 2.3.34,Struts 2.5 to 2.5.16 此漏洞影响范围非常小,要求配置条件比较苛刻,同时,一些特定版本没有看到有沙盒绕过,说以,目前exp只是基于S2-045改写的,所以exp并不是所有版本都能用,...

    SSH框架(Struts 2.3.25 + Spring-framework-4.2.2 +Hibernate-5.0.2)

    Struts 2.3.25 + spring-4.2.2 + hibernate-5.0.2 Apache Struts Struts 2.3.24.1 has been released on 24 september 2015. http://struts.apache.org/download.cgi#struts23241 spring-framework-4.2.2.RELEASE-...

    最新版本的Struts2+Spring4+Hibernate4框架整合

    整合使用最新版本的三大框架(即Struts2、Spring4和Hibernate4),搭建项目架构原型。 项目架构原型:Struts2.3.16 + Spring4.1.1 + Hibernate4.3.6。 此外,还有:log4j、slf4j、junit4、ehcache等知识点。 项目...

    jsp2.0 应用教程 光盘

    (1)本书和随书附送的光盘中涉及的文档、软件、图片和代码等项目仅供教学使用。 (2)本书实例源程序运行测试环境为: JDK 5.0 update 6和JDK 6.0 beta Tomcat 5.5.12 MySQL 5.0.16 (3)本书涉及的共享软件或免费软件...

    struts hibernate spring 集成时使用依赖注解的方式的秘籍

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop=...

    Spring4.0+Hibernate4.0+Struts2.3整合案例

    Spring4.0+Hibernate4.0+Struts2.3整合案例:实现增删改查。 ===================== application.xml: <?xml version="1.0" encoding="UTF-8"?> xmlns="http://www.springframework.org/schema/beans" xmlns:xsi=...

    Struts2开发常用jar包

    包含struts2-core-2.5.10.1.jar,struts2-jfreechart-plugin-2.5.10.1.jar,struts2-json-plugin-2.5.10.1.jar,struts2-junit-plugin-2.5.10.1.jar,struts2-bean-validation-plugin-2.5.10.1.jar,struts2-cdi-...

    struts2_S016_S017_repair

    官方描述: ... ... 官方建议修复方案:升级到最新版本 struts-2.3.15.1 但通常现有系统升级,可能导致不稳定及与其他...鉴于此csdn网友jzshmyt整理了一种既可以不用升级现有struts版本,有能完美解决这两个漏洞的方案,

    Struts 与 Velocity 的集成(http://www-128.ibm.com/deve)

    文章对应代码 博文链接:https://aideqianfang.iteye.com/blog/243021

    WABACUS整合Struts2、DWZ的项目源码

    基于WABACUS3.5+Struts2.3.8+DWZ1.4.4程序框架 修改简单改造了WABACUS3.5:实现了在Wabacus.report.config文件中设置报表文件配置XML和报表资源XML文件时文件路径和文件名称都可以使用通配符的功能,以方便以后将...

    搭建struts2框架

    struts2框架的详细搭建 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" ...

    Flex+Struts2+JSON实现Flex和后台的HTTP Service请求

    NULL 博文链接:https://zyw090111.iteye.com/blog/626511

    Hello Struts2 ——Struts2 的配置和第一个Struts2小程序

    NULL 博文链接:https://wang4717.iteye.com/blog/804885

    commons-dbcp-1.2.1.jar commons-pool-1.3.jar struts-legacy.jar

    commons-dbcp-1.2.1.jar commons-pool-1.3.jar struts-legacy.jar

Global site tag (gtag.js) - Google Analytics