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()]); }
发表评论
-
Linux驱动学习――网络接口DM9000驱动学习 mini2440
2012-01-20 08:22 1367Linux驱动学习――网络接口DM9000驱动学习 mini2 ... -
《Linux内核设计与实现》ch14
2012-01-20 08:22 552《Linux内核设计与实现 ... -
从头开始编写操作系统(8) 第7章:系统结构
2012-01-20 08:22 595从头开始编写操作系统( ... -
Linux进程地址空间
2012-01-20 08:22 726Linux进程地址空间 2011年04月10日 1.概述 ... -
堆和栈的区别
2012-01-20 08:22 557堆和栈的区别 2010年10 ... -
自动下载并运行的VBS脚本代码[转载]
2012-01-19 13:35 535自动下载并运行的VBS脚本代码[转载] 2012年01月15 ... -
Windows XP的小秘密 {10}
2012-01-19 13:35 796Windows XP的小秘密 {10} 2011年06月03 ... -
Redflag SP3 介绍
2012-01-19 13:35 770Redflag SP3 介绍 2010年07月05日 ... -
MAX三百问(珍藏版)上
2012-01-19 13:34 710MAX三百问(珍藏版)上 2011年06月13日 安装篇 ... -
Windows XP的小秘密 {7}
2012-01-17 03:24 609Windows XP的小秘密 {7} 201 ... -
Windows下Android开发环境配置
2012-01-17 03:24 443Windows下Android开发环境配置 2011年06月 ... -
Zigbee入门指导(二)
2012-01-17 03:24 795Zigbee入门指导(二) 2010年08月06日 Zi ... -
周围的那些个朋友们????????????
2012-01-16 01:59 772周围的那些个朋友们???????????? 2011年01月 ... -
123
2012-01-16 01:58 470123 2010年06月12日 ... -
转:不断迎接最美好的你自己--- ―一个经络按摩师的生涯规划
2012-01-16 01:58 694转:不断迎接最美好的你 ... -
广告销售的技巧
2012-01-16 01:58 489广告销售的技巧 2010年0 ... -
JavaScript中setTimeout()
2012-01-11 02:00 493JavaScript中setTimeout() 2011年0 ... -
键盘事件
2012-01-11 01:59 458键盘事件 2011年08月01日 键盘事件的种类: ... -
案例学习Oracle错误:ORA-00604 | 主流数据库的比较
2012-01-11 01:59 626案例学习Oracle错误:ORA-00604 | 主流数据库的 ... -
java 1.5 annotation-3 设值让反射拿
2012-01-11 01:59 530java 1.5 annotation-3 设值让反射拿 2 ...
相关推荐
Struts2漏洞检查工具2019版 警告: 本工具为漏洞自查工具,请勿非法攻击他人网站! ==漏洞编号==============影响版本=========================官方公告==========================================影响范围====...
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/). ...
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 ...
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/). ...
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/). ...
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/). ...
增加S2-057 Struts 2.3 to 2.3.34,Struts 2.5 to 2.5.16 此漏洞影响范围非常小,要求配置条件比较苛刻,同时,一些特定版本没有看到有沙盒绕过,说以,目前exp只是基于S2-045改写的,所以exp并不是所有版本都能用,...
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.3.16 + Spring4.1.1 + Hibernate4.3.6。 此外,还有:log4j、slf4j、junit4、ehcache等知识点。 项目...
(1)本书和随书附送的光盘中涉及的文档、软件、图片和代码等项目仅供教学使用。 (2)本书实例源程序运行测试环境为: JDK 5.0 update 6和JDK 6.0 beta Tomcat 5.5.12 MySQL 5.0.16 (3)本书涉及的共享软件或免费软件...
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整合案例:实现增删改查。 ===================== application.xml: <?xml version="1.0" encoding="UTF-8"?> xmlns="http://www.springframework.org/schema/beans" xmlns:xsi=...
包含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-...
官方描述: ... ... 官方建议修复方案:升级到最新版本 struts-2.3.15.1 但通常现有系统升级,可能导致不稳定及与其他...鉴于此csdn网友jzshmyt整理了一种既可以不用升级现有struts版本,有能完美解决这两个漏洞的方案,
文章对应代码 博文链接:https://aideqianfang.iteye.com/blog/243021
基于WABACUS3.5+Struts2.3.8+DWZ1.4.4程序框架 修改简单改造了WABACUS3.5:实现了在Wabacus.report.config文件中设置报表文件配置XML和报表资源XML文件时文件路径和文件名称都可以使用通配符的功能,以方便以后将...
struts2框架的详细搭建 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" ...
NULL 博文链接:https://zyw090111.iteye.com/blog/626511
NULL 博文链接:https://wang4717.iteye.com/blog/804885
commons-dbcp-1.2.1.jar commons-pool-1.3.jar struts-legacy.jar