国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Struts1.1b3部分源代碼分析.

2019-11-17 06:27:58
字體:
來源:轉載
供稿:網友

  Struts1.1部分源代碼分析
一:說明
本文針對Struts1.1b3做分析,主要希望通過對源代碼的分析闡述Struts1.1的工作方式。
本文不適合初學者參考,適合具有一定基于Struts開發的程序員參考。
下面的描述;里面將會對ActionServlet,RequestPRocessor,ModuleConfig等幾個類做一些
說明。以注釋源代碼的方式,說明取工作流程。
非凡申明:Struts1.1代碼版權屬于Apache遵循The Apache Software License, Version 1.1.
本文版權屬于孤魂一笑個人所有,任何個人或組織希望轉載,請與我聯系。并獲得我的授權
方可轉載。

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


action
org.apache.struts.action.ActionServlet
org.apache.struts.tiles.ActionComponentServlet -->

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-debug
0


definitions-parser-details
0


definitions-parser-validate
true



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


validate
true


debug
2


detail
2



application
org.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 bundle
initInternal();
//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();

// Initialize modules as needed
//在Attribute中保存類實例
getServletContext().setAttribute(Globals.ACTION_SERVLET_KEY, this);
//根據配置文件生成ModuleConfig,這是很重要的一步.下面會專門分析
//在tiles的配置中先解析注釋為"Mark 0"的一個配置文件:/WEB-INF/struts-config.xml
//使用initModuleConfig方法解析XML文件.
//參數為prefix:"",paths:"/WEB-INF/struts-config.xml"
ModuleConfig moduleConfig = initModuleConfig("", config);
//初始化Message
initModuleMessageResources(moduleConfig);
//初始化JDBC DataSource
initModuleDataSources(moduleConfig);
//初始化PlunIn
initModulePlugIns(moduleConfig);

moduleConfig.freeze();
//在Struts1.1以后可以使用多個配置文件,在解析完默認的配置文件也就是上面提到的
//注釋為"Mark 0"的一個配置文件:/WEB-INF/struts-config.xml后解析其他的配置文件
Enumeration names = getServletConfig().getInitParameterNames();
//依次解析注釋為"Mark 1"、"Mark 2"、"Mark 3"對應配置文件
while (names.hasMoreElements()) {
//每一個配置文件的文件名
String name = (String) names.nextElement();
if (!name.startsWith("config/")) {
continue;
}
//
String prefix = name.substring(6);
moduleConfig = initModuleConfig
(prefix, getServletConfig().getInitParameter(name));

initModuleMessageResources(moduleConfig);
initModuleDataSources(moduleConfig);
initModulePlugIns(moduleConfig);
moduleConfig.freeze();
}
destroyConfigDigester();

}
/**
* 此方法使用Digester解析XML,關于使用Digester的介紹參看我的另外一篇文章
*



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 柳河县| 白河县| 拉孜县| 马边| 苍山县| 南漳县| 荣昌县| 平远县| 郎溪县| 文水县| 科技| 九江市| 台南县| 东明县| 南华县| 读书| 虎林市| 耒阳市| 绵阳市| 雅江县| 鄯善县| 柯坪县| 浙江省| 安达市| 宁国市| 台东县| 来凤县| 永州市| 临颍县| 延津县| 香河县| 临沧市| 新平| 荆门市| 托里县| 会昌县| 凤冈县| 漾濞| 明星| 荔浦县| 大余县|