云下的天空

          堅(jiān)持 隨心而動(dòng) 走自己的路

           

          Tomcat中web.xml文件的詳細(xì)說(shuō)明

          原文轉(zhuǎn)自:

          http://blog.csdn.net/pathfinder163/archive/2009/09/02/4506817.aspx


          <?xml version="1.0" encoding="GB2312"?> <!-- 
          Web.xml依次定議了如下元素: 
          <web-app> 

          <display-name></display-name> 定義了WEB應(yīng)用的名字 

          <description></description> 聲明WEB應(yīng)用的描述信息 

          <filter></filter> 

          <filter-mapping></filter-mapping>
           

          <servlet></servlet> 

          <servlet-mapping></servlet-mapping> 

          <session-config></session-config> 

          <welcome-file-list></welcome-file-list> 

          <taglib></taglib> 

          <resource-ref></resource-ref> 

          <security-constraint></security-constraint> 

          <login-config></login-config> 

          </web-app> 
          在web.xml中元素定義的先后順序不能顛倒,否則Tomcat服務(wù)器可能會(huì)拋出SAXParseException. 
          --> 
          <!DOCTYPE web-app PUBLIC "-//Sun Microsystems,Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> 
          <web-app>

          <display-name>Sample Application</display-name>

          <description> 
          This is a Sample Application 
          </description>

          <!-- 
          filter 配置Servlet過(guò)濾器 
          filter-name 定義過(guò)濾器的名字。當(dāng)有多個(gè)過(guò)濾器時(shí),不能同名 
          filter-class 指定實(shí)現(xiàn)這一過(guò)濾的類(lèi),這個(gè)類(lèi)負(fù)責(zé)具體的過(guò)濾事務(wù) 
          --> 
          <filter> 
          <filter-name>SampleFilter</filter-name> 
          <filter-class>mypack.SampleFilter</filter-class> 
          </filter>

          <!-- 
          filter-mapping 設(shè)定過(guò)濾器負(fù)責(zé)過(guò)濾的URL 
          filter-name 過(guò)濾器名。這里的名字一定要和filter中的過(guò)濾器名匹配 
          url-pattern 指定過(guò)濾器負(fù)責(zé)過(guò)濾的URL 
          --> 
          <filter-mapping> 
          <filter-name>SampleFilter</filter-name> 
          <url-pattern>*.jsp</url-pattern> 
          </filter-mapping>

          <!-- 
          servlet 配置Servlet. 
          servlet-name 定義Servlet的名字 
          servlet-class 指定實(shí)現(xiàn)這個(gè)servlet的類(lèi) 
          init-param 定義Servlet的初始化參數(shù)和參數(shù)值,可有多個(gè)init-param。在servlet類(lèi)中通過(guò)getInitParamenter(String name)方法訪問(wèn)初始化參數(shù) 
          load-on-startup 指定當(dāng)Web應(yīng)用啟動(dòng)時(shí),裝載Servlet的次序。 
          當(dāng)值為正數(shù)或零時(shí):Servlet容器先加載數(shù)值小的servlet,再依次加載其他數(shù)值大的servlet. 
          當(dāng)值為負(fù)或未定義:Servlet容器將在Web客戶首次訪問(wèn)這個(gè)servlet時(shí)加載它 
          --> 
          <servlet> 
          <servlet-name>SampleServlet</servlet-name> 
          <servlet-class>mypack.SampleServlet</servlet-class> 
          <init-param> 
          <param-name>initParam1</param-name> 
          <param-value>2</param-value> 
          </init-param> 
          <load-on-startup>1</load-on-startup> 
          </servlet>

          <!-- 
          配置servlet映射(下面代碼為SampleServlet指定的相對(duì)URL為"/sample": 
          servlet-name 指定servlet的名字,這里的名字應(yīng)該和<Servlet>元素中定義的名字匹配。 
          url-pattern 指定訪問(wèn)這個(gè)servlet的URL。只需給出相對(duì)路徑。 
          --> 
          <servlet-mapping> 
          <servlet-name>SampleServlet</servlet-name> 
          <url-pattern>/sample</url-pattern> 
          </servlet-mapping>

          <!--配置session session用來(lái)設(shè)定HttpSession的生命周期。單位(秒)--> 
          <session-config> 
          <session-timeout>30</session-timeout> 
          </session-config>

          <!--配置Wel0come0文件清單--> 
          <welcome-file-list> 
          <welcome-file>login.jsp</welcome-file> 
          <welcome-file>index.htm</welcome-file> 
          </welcome-file-list>

          <!-- 
          配置Tag Library 
          taglib-uri 設(shè)定Tag Library的唯一標(biāo)識(shí)符,在Web應(yīng)用中將根據(jù)這一標(biāo)識(shí)符來(lái)引用Tag Library 
          taglib-location 指定和Tag Library對(duì)應(yīng)的TLD文件的位置 
          --> 
          <taglib> 
          <taglib-uri>/mytaglib</taglib-uri> 
          <taglib-location>/WEB-INF/mytaglib.tld</taglib-location> 
          </taglib>

          <!-- 
          配置資源引用 
          description 對(duì)所引用的資源的說(shuō)明 
          res-ref-name 指定所引用資源的JNDI名字 
          res-type 指定所引用資源的類(lèi)名字 
          res-auth 指定管理所引用資源的Manager,它有兩個(gè)可選值: 
          Container:由容器來(lái)創(chuàng)建和管理resource 
          Application:同WEB應(yīng)用來(lái)創(chuàng)建和管理Resource 
          --> 
          <resource-ref> 
          <description>DB Connection</description> 
          <res-ref-name>jdbc/sampleDB</res-ref-name> 
          <res-type>javax.sql.DataSource</res-type> 
          <res-auth>Container</res-auth> 
          </resource-ref>

          <!-- 
          配置安全約束(以下代碼指定當(dāng)用戶訪問(wèn)該WEB應(yīng)用下的所有資源時(shí),必須具備guest角色) 
          web-resource-collection 聲明受保護(hù)的WEB資源 
          auth-constraint 聲明可以訪問(wèn)受保護(hù)資源的角色,可以包含多個(gè)<role-name>子元素

          web-resource-name 標(biāo)識(shí)受保護(hù)的WEB資源 
          url-pattern 指定受保護(hù)的URL路徑 
          --> 
          <Security-constraint> 
          <web-resource-collection> 
          <web-resource-name>sample appliction</web-resource-name> 
          <url-pattern>/*</url-pattern> 
          </web-resource-collection> 
          <auth-constraint> 
          <role-name>guest</role-name> 
          </auth-constraint> 
          </Security-constraint>


          <!-- 
          配置安全驗(yàn)證登錄界面:指定當(dāng)WEB客戶訪問(wèn)受保護(hù)的WEB資源時(shí),系統(tǒng)彈出的登錄對(duì)話框的類(lèi)型。 
          auth-method 指定驗(yàn)證方法,它有三個(gè)可選值:BASIC(基本驗(yàn)證)、DIGEST(摘要驗(yàn)證)、FORM(表單驗(yàn)證) 
          realm-name 設(shè)定安全域的名稱(chēng) 
          form-login-config 當(dāng)驗(yàn)證方法為FORM時(shí),配置驗(yàn)證網(wǎng)頁(yè)和出錯(cuò)網(wǎng)頁(yè) 
          form-login-page 當(dāng)驗(yàn)證方法為FORM時(shí),設(shè)定驗(yàn)證網(wǎng)頁(yè) 
          form-error-page 當(dāng)驗(yàn)證方法為FORM時(shí),設(shè)定出錯(cuò)網(wǎng)頁(yè) 
          --> 
          <login-config> 
          <auth-method>FORM</auth-method> 
          <realm-name> 
          Tomcat Server Configuration form-Based Authentication Area 
          </realm-name> 
          <form-login-config> 
          <form-login-page>/login.jsp</form-login-page> 
          <form-error-page>/error.jsp</form-error-page> 
          </form-login-config> 
          </login-config>

          <!--配置對(duì)安全驗(yàn)證角色的引用--> 
          <security-role> 
          <description> 
          The role that is required to log into the sample application 
          </description> 
          <role-name>guest</role-name> 
          </security-role> 

          </web-app>

          <?xml version="1.0" encoding="GB2312"?> <!-- 
          Web.xml依次定議了如下元素: 
          <web-app> 
          <display-name></display-name> 定義了WEB應(yīng)用的名字 
          <description></description> 聲明WEB應(yīng)用的描述信息 
          <filter></filter> 
          <filter-mapping></filter-mapping> 
          <servlet></servlet> 
          <servlet-mapping></servlet-mapping> 
          <session-config></session-config> 
          <welcome-file-list></welcome-file-list> 
          <taglib></taglib> 
          <resource-ref></resource-ref> 
          <security-constraint></security-constraint> 
          <login-config></login-config> 
          </web-app> 
          在web.xml中元素定義的先后順序不能顛倒,否則Tomcat服務(wù)器可能會(huì)拋出SAXParseException. 
          --> 
          <!DOCTYPE web-app PUBLIC "-//Sun Microsystems,Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> 
          <web-app>

          <display-name>Sample Application</display-name>

          <description> 
          This is a Sample Application 
          </description>

          <!-- 
          filter 配置Servlet過(guò)濾器 
          filter-name 定義過(guò)濾器的名字。當(dāng)有多個(gè)過(guò)濾器時(shí),不能同名 
          filter-class 指定實(shí)現(xiàn)這一過(guò)濾的類(lèi),這個(gè)類(lèi)負(fù)責(zé)具體的過(guò)濾事務(wù) 
          --> 
          <filter> 
          <filter-name>SampleFilter</filter-name> 
          <filter-class>mypack.SampleFilter</filter-class> 
          </filter>

          <!-- 
          filter-mapping 設(shè)定過(guò)濾器負(fù)責(zé)過(guò)濾的URL 
          filter-name 過(guò)濾器名。這里的名字一定要和filter中的過(guò)濾器名匹配 
          url-pattern 指定過(guò)濾器負(fù)責(zé)過(guò)濾的URL 
          --> 
          <filter-mapping> 
          <filter-name>SampleFilter</filter-name> 
          <url-pattern>*.jsp</url-pattern> 
          </filter-mapping>

          <!-- 
          servlet 配置Servlet. 
          servlet-name 定義Servlet的名字 
          servlet-class 指定實(shí)現(xiàn)這個(gè)servlet的類(lèi) 
          init-param 定義Servlet的初始化參數(shù)和參數(shù)值,可有多個(gè)init-param。在servlet類(lèi)中通過(guò)getInitParamenter(String name)方法訪問(wèn)初始化參數(shù) 
          load-on-startup 指定當(dāng)Web應(yīng)用啟動(dòng)時(shí),裝載Servlet的次序。 
          當(dāng)值為正數(shù)或零時(shí):Servlet容器先加載數(shù)值小的servlet,再依次加載其他數(shù)值大的servlet. 
          當(dāng)值為負(fù)或未定義:Servlet容器將在Web客戶首次訪問(wèn)這個(gè)servlet時(shí)加載它 
          --> 
          <servlet> 
          <servlet-name>SampleServlet</servlet-name> 
          <servlet-class>mypack.SampleServlet</servlet-class> 
          <init-param> 
          <param-name>initParam1</param-name> 
          <param-value>2</param-value> 
          </init-param> 
          <load-on-startup>1</load-on-startup> 
          </servlet>

          <!-- 
          配置servlet映射(下面代碼為SampleServlet指定的相對(duì)URL為"/sample": 
          servlet-name 指定servlet的名字,這里的名字應(yīng)該和<Servlet>元素中定義的名字匹配。 
          url-pattern 指定訪問(wèn)這個(gè)servlet的URL。只需給出相對(duì)路徑。 
          --> 
          <servlet-mapping> 
          <servlet-name>SampleServlet</servlet-name> 
          <url-pattern>/sample</url-pattern> 
          </servlet-mapping>

          <!--配置session session用來(lái)設(shè)定HttpSession的生命周期。單位(秒)--> 
          <session-config> 
          <session-timeout>30</session-timeout> 
          </session-config>

          <!--配置Wel0come0文件清單--> 
          <welcome-file-list> 
          <welcome-file>login.jsp</welcome-file> 
          <welcome-file>index.htm</welcome-file> 
          </welcome-file-list>

          <!-- 
          配置Tag Library 
          taglib-uri 設(shè)定Tag Library的唯一標(biāo)識(shí)符,在Web應(yīng)用中將根據(jù)這一標(biāo)識(shí)符來(lái)引用Tag Library 
          taglib-location 指定和Tag Library對(duì)應(yīng)的TLD文件的位置 
          --> 
          <taglib> 
          <taglib-uri>/mytaglib</taglib-uri> 
          <taglib-location>/WEB-INF/mytaglib.tld</taglib-location> 
          </taglib>

          <!-- 
          配置資源引用 
          description 對(duì)所引用的資源的說(shuō)明 
          res-ref-name 指定所引用資源的JNDI名字 
          res-type 指定所引用資源的類(lèi)名字 
          res-auth 指定管理所引用資源的Manager,它有兩個(gè)可選值: 
          Container:由容器來(lái)創(chuàng)建和管理resource 
          Application:同WEB應(yīng)用來(lái)創(chuàng)建和管理Resource 
          --> 
          <resource-ref> 
          <description>DB Connection</description> 
          <res-ref-name>jdbc/sampleDB</res-ref-name> 
          <res-type>javax.sql.DataSource</res-type> 
          <res-auth>Container</res-auth> 
          </resource-ref>

          <!-- 
          配置安全約束(以下代碼指定當(dāng)用戶訪問(wèn)該WEB應(yīng)用下的所有資源時(shí),必須具備guest角色) 
          web-resource-collection 聲明受保護(hù)的WEB資源 
          auth-constraint 聲明可以訪問(wèn)受保護(hù)資源的角色,可以包含多個(gè)<role-name>子元素

          web-resource-name 標(biāo)識(shí)受保護(hù)的WEB資源 
          url-pattern 指定受保護(hù)的URL路徑 
          --> 
          <Security-constraint> 
          <web-resource-collection> 
          <web-resource-name>sample appliction</web-resource-name> 
          <url-pattern>/*</url-pattern> 
          </web-resource-collection> 
          <auth-constraint> 
          <role-name>guest</role-name> 
          </auth-constraint> 
          </Security-constraint>


          <!-- 
          配置安全驗(yàn)證登錄界面:指定當(dāng)WEB客戶訪問(wèn)受保護(hù)的WEB資源時(shí),系統(tǒng)彈出的登錄對(duì)話框的類(lèi)型。 
          auth-method 指定驗(yàn)證方法,它有三個(gè)可選值:BASIC(基本驗(yàn)證)、DIGEST(摘要驗(yàn)證)、FORM(表單驗(yàn)證) 
          realm-name 設(shè)定安全域的名稱(chēng) 
          form-login-config 當(dāng)驗(yàn)證方法為FORM時(shí),配置驗(yàn)證網(wǎng)頁(yè)和出錯(cuò)網(wǎng)頁(yè) 
          form-login-page 當(dāng)驗(yàn)證方法為FORM時(shí),設(shè)定驗(yàn)證網(wǎng)頁(yè) 
          form-error-page 當(dāng)驗(yàn)證方法為FORM時(shí),設(shè)定出錯(cuò)網(wǎng)頁(yè) 
          --> 
          <login-config> 
          <auth-method>FORM</auth-method> 
          <realm-name> 
          Tomcat Server Configuration form-Based Authentication Area 
          </realm-name> 
          <form-login-config> 
          <form-login-page>/login.jsp</form-login-page> 
          <form-error-page>/error.jsp</form-error-page> 
          </form-login-config> 
          </login-config>

          <!--配置對(duì)安全驗(yàn)證角色的引用--> 
          <security-role> 
          <description> 
          The role that is required to log into the sample application 
          </description> 
          <role-name>guest</role-name> 
          </security-role> 
          </web-app>

          posted on 2011-06-02 17:19 天空布藍(lán) 閱讀(875) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): JAVA EE


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿

          隨筆分類(lèi)

          隨筆檔案

          Flex學(xué)習(xí)鏈接

          搜索

          •  

          最新評(píng)論

          • 1.?re: tomcat7的配置
          • 新建變量名: TOMCAT_HOME 應(yīng)該為CATALINA_HOME
          • --houkai
          • 2.?re: tomcat7的配置
          • 確實(shí)是的@寒澈
          • --houkai
          • 3.?re: tomcat7的配置
          • @ftp123
            你娘里個(gè)大雪碧 里面會(huì)有common這個(gè)文件夾嗎 不知道還尼瑪在這瞎比比 純尼瑪誤導(dǎo)人 我最?lèi)盒牡木褪沁@樣沒(méi)事裝逼的人 艸
          • --cao
          • 4.?re: tomcat7的配置
          • 從哪抄來(lái)的,是抄的,你也說(shuō)聲啊,要不自己測(cè)試下也可以,害人測(cè)試半天。
          • --ftp123
          • 5.?re: tomcat7的配置
          • %TOMCAT_HOME%\common\lib 從tomcat6.0開(kāi)始已經(jīng)沒(méi)有common文件夾了,直接用\lib,害我找了半天common文件夾啊,趕快改過(guò)來(lái)吧
          • --寒澈

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 多伦县| 获嘉县| 芒康县| 颍上县| 阜新市| 南靖县| 陇南市| 通海县| 大宁县| 孟州市| 屏山县| 务川| 宁海县| 常熟市| 屏南县| 临桂县| 桂平市| 剑河县| 社会| 宜兰市| 噶尔县| 纳雍县| 息烽县| 保康县| 南汇区| 泾源县| 宁乡县| 金坛市| 碌曲县| 澎湖县| 金川县| 句容市| 芒康县| 承德县| 丹巴县| 武威市| 分宜县| 河源市| 双桥区| 徐水县| 本溪市|