RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:9:30-18:00
你可能遇到了下面的问题
关闭右侧工具栏
Struts1.1b3部分源代码分析
  • 作者:zhaozj
  • 发表时间:2020-12-23 11:03
  • 来源:未知

Struts1.1b3部分源代码分析. 阅读次数3476

出处 CN-JAVA原创:孤魂一笑    


Struts1.1部分源代码分析一:说明本文针对Struts1.1b3做分析,主要希望通过对源代码的分析阐述Struts1.1的工作方式。本文不适合初学者参考,适合具有一定基于Struts开发的程序员参考。下面的描述;里面将会对ActionServlet,RequestProcessor,ModuleConfig等几个类做一些说明。以注释源代码的方式,说明取工作流程。特别申明:Struts1.1代码版权属于Apache遵循The Apache Software License, Version 1.1.本文版权属于孤魂一笑个人所有,任何个人或组织希望转载,请与我联系。并获得我的授权方可转载。(转贴时因找不到作者的联系方式,作者可与我联系duoshan@hotmail.com)

二:ActionServlet分析我们先来看一下使用Struts的配置文件。

actionorg.apache.struts.action.ActionServlet

definitions-config/WEB-INF/tiles-defs.xml,/WEB-INF/tiles-tests-defs.xml,/WEB-INF/tiles-tutorial-defs.xml,/WEB-INF/tiles-examples-defs.xml

definitions-debug0

definitions-parser-details0

definitions-parser-validatetrue

 

config/WEB-INF/struts-config.xml

 

config/examples/WEB-INF/struts-examples-config.xml

 

config/test/WEB-INF/struts-tests-config.xml

 

config/tutorial/WEB-INF/struts-tutorial-config.xml

validatetrue

debug2

detail2

 

applicationorg.apache.struts.webapp.tiles.dev1-1.ApplicationResources

2

 

action*.do

 

接下来我们来看一下ActionServlet的具体使用javax.servlet.http.HttpServlet||-->org.apache.struts.action.ActionServlet所以本质上ActionServlet是一个普通的servlet,负责处理.do为后缀的Http请求.servlet在执行doGet(),doPost(),之前先调用init(),以下我们先分析一下init()方法/*** Initialize this servlet. Most of the processing has been factored into* support methods so that you can override particular functionality at a* fairly granular level.

* servlet初始化操作,注意初始化顺序* @exception ServletException if we cannot configure ourselves correctly*/public void init() throws ServletException {//注意初始化的顺序//Initialize our internal MessageResources bundleinitInternal();//Initialize other global characteristics of the controller servlet//处理一些全局变量的设置如:debug,detail等initOther();//Initialize the servlet mapping under which our controller servlet//is being accessed. This will be used in the &html:form>//tag to generate correct destination URLs for form submissions//主要是注册DTD文件以及解析web.xml关于ActionServlet的配置。如后缀名等.// Configure the processing rules that we need// digester.addCallMethod("web-app/servlet-mapping",// "addServletMapping", 2);// digester.addCallParam("web-app/servlet-mapping/servlet-name", 0);// digester.addCallParam("web-app/servlet-mapping/url-pattern", 1);//initServlet()的上面一段将把Struts默认的后缀名从web.xml中解析得到//也就是web.xml中的如下配置:////action//*.do//默认以.do结尾的请求都将由Struts来处理,你可以自己修改//initServlet();