servlet 中 web.xml 備忘 總結

來源:互聯網
上載者:User

標籤:des   style   class   code   java   tar   

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<icon> 
<small-icon>/images/app_small.gif</small-icon> 
<large-icon>/images/app_large.gif</large-icon> 
</icon> 

/*

icon:指定web應用程式的大表徵圖和小表徵圖

*/

<display-name>Tomcat Example</display-name> //Web 應用程式名稱

<disciption>Tomcat Example servlets and JSP pages.</disciption> //Web應用描述

 


<init-param>//servlet範圍內的參數,通過this.getInitParameter("param1")取得
<param-name>data2</param-name>
<param-value>YYYYYYYYYYYYY</param-value>
</init-param>

<context-param> //application範圍內的參數,存放在servletcontext中(一般在spring中)getServletContext().getInitParameter("context/param")得到

    <param-name>ContextParameter</para-name> 
    <param-value>test</param-value> 
    <description>It is a test parameter.</description> 
</context-param> 

 

<servlet>
<servlet-name>ServletDemo</servlet-name> //指定Servlet名字
<servlet-class>com.bird.servlet.ServletDemo</servlet-class>//指定Servlet所在路徑

/*

這表示位於WEB-INF/classes/com/bird/servlet/ServletDemo的servlet已經得到了註冊名ServletDemo。給servlet一個名稱具有兩個主要的含義。首先,初始化參數、定製的URL模式以及其他定製通過此註冊名而不是類名引用此servlet。其次,可在URL而不是類名中使用此名稱

*/

<load-on-startup>1</load-on-startup>// 伺服器啟動是是否裝載這個servlet,0:不裝載 其他數字依次是裝載數字
</servlet>




<servlet-mapping>// url訪問映射模式,通過下面的url-pattern得到匹配模式,從而找到相應的servlet處理器
<servlet-name>ServletDemo</servlet-name>
<url-pattern>*do</url-pattern> 
</servlet-mapping>


<session-config>//控制會話逾時(單位是分鐘)
<session-timeout>180</session-timeout>
</session-config>

<error-page> //通過錯誤碼配置指定錯誤頁位置

      <error-code>404</error-code> 

      <location>/NotFound.jsp</location> 
</error-page>

 

    MIME類型配置 
   <mime-mapping> 
      <extension>htm</extension> 
      <mime-type>text/html</mime-type> 
   </mime-mapping> 

資源工廠配置 
   <resource-ref> 
       <res-ref-name>mail/Session</res-ref-name> 
       <res-type>javax.mail.Session</res-type> 
       <res-auth>Container</res-auth> 
   </resource-ref> 
   設定資料庫串連池就可在此配置: 
   <resource-ref> 
       <description>JNDI JDBC DataSource of shop</description> 
       <res-ref-name>jdbc/sample_db</res-ref-name> 
       <res-type>javax.sql.DataSource</res-type> 
       <res-auth>Container</res-auth> 
   </resource-ref> 


<welcome-file-list>//指定預設訪問頁面
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.