The most complete Web. XML configuration file element in history

Source: Internet
Author: User
Tags event listener tld

I. Web. XML configuration file Common elements and their meaning preview

 1 <web-app> 2 3 <!--defines the name of the Web App--4 <display-name></display-name> 5 6 <!--statement      Description of the Web App--7 <description></description> 8 9 <!--Context-param Element declares an application-scoped initialization parameter-->10 <context-param></context-param>11 <!--The filter element relates a name to a class that implements the Javax.servlet.Filter interface-->13 < Filter></filter>14 <!--Once a filter is named, use the filter-mapping element to correlate it with one or more servlet or JSP pages-->16 <filter -mapping></filter-mapping>17 <!--The version 2.3 of the Servlet API adds support for event listeners, which are notified when a session or servlet environment is established, modified, and deleted. The listener element indicates that the event listener class-->20 <listener></listener>21 <!--to set initialization parameters or customize U to a servlet or JSP page RL, you must first name the servlet or JSP page. The-->24 servlet element is used to accomplish this task. <servlet></servlet>25 <!--server typically provides a default url:htt for Servlets P://host/webappprefix/servlet/servletname. 27 However, this URL is often changed so that the servlet can access the initialization parameters or make it easier to handle relative URLs. 28 when changing the default URL, use the Servlet-mapping element-->29 <servlet-mapping></servlet-mapping>30 <!--If a session has not been accessed for a certain amount of time, the server can discard it to save memory 。 You can explicitly set a time-out value for a single Session object by using the HttpSession Setmaxinactiveinterval method, or you can use the Session-config element to make a default timeout-->33 <session-      Config></session-config>34 <!--If the Web app has a special file that you want to guarantee to assign to them a specific MIME type, the mime-mapping element provides this assurance-->36 <mime-mapping></mime-mapping>37 <!--instructs the server which file to use when it receives a URL that references a directory name instead of a file name-->39 <welcome-fi Le-list></welcome-file-list>40 <!--when a specific HTTP status code is returned, or when a particular type of exception is thrown, the page that will be displayed is made-->42 <error-pag e></error-page>43 <!--specify aliases for tag library descriptor files (tag Libraryu descriptor file). This feature enables you to change the location of TLD files by 45 without editing the JSP pages that use these files-->46 <taglib></taglib>47 <!--declares a resource-related management object -->49 <resource-env-ref></resource-env-ref>50 <!--declares an external resource used by a resource factory-->52 <resource -ref></resource-ref>53 <!--develop URLs that should be protected. it withLogin-config elements combined with-->55 <security-constraint></security-constraint>56 <!--Specify how the server should give access to the protected User authorization for the page. It is used in conjunction with the Sercurity-constraint element-->58 <login-config></login-config>59 <!--gives a list of security roles that will appear in the S The Ervlet element within the security-role-ref element of the Role-name child element. 61 declaring roles separately makes it easier for advanced Ides to handle security information-->62 <security-role></security-role>63 <!--declaring environment items for web Apps -->65 <env-entry></env-entry>66 <!--declares a reference to the home directory of an EJB-->68 <ejb-ref></ejb-ref  >69 <!--declares the application of an EJB's local home directory-->71 <ejb-local-ref></ejb-local-ref>72 </web-app>

Ii. detailed description of each configuration element

1.Web app Icon: Indicates large icons and small icons used by IDE and GUI tools to represent web apps

1 <icon>  2      <small-icon>/images/app_small.gif</small-icon>  3      <large-icon >/images/app_large.gif</large-icon>  4  </icon>

2.Web App Name: Provides a name that GUI tools may use to mark this particular Web app

1 <display-name>tomcat example</display-name>

3.WEB Application Description: Give descriptive text that is relevant to this

1 <disciption>tomcat Example servlets and JSP pages.</disciption>

4. Context parameters: Declaring application-scoped initialization parameters

1 <context-param>2      <param-name> parameter name </para-name>3      <param-value> argument value </ Param-value>4      <description> parameter description </description>5  </context-param>

The servlet can be obtained by Getservletcontext () getinitparameter ("Context/param").

5. Filter configuration: Associate a name with a class that implements the Javaxs.servlet.Filter interface

1 <filter> 2      <filter-name>setCharacterEncoding</filter-name> 3      <filter-class> Com.mytest.setcharacterencodingfilter</filter-class> 4      <init-param> 5          <param-name> Encoding</param-name> 6          <param-value>GB2312</param-value> 7      </init-param> 8  </filter> 9  <filter-mapping>10      <filter-name>setCharacterEncoding</filter-name>      <url-pattern>/*</url-pattern>12  </filter-mapping>

6. Listener Configuration

1 <listener>2      <listerner-class>org.springframework.web.context.contextloaderlistener</ Listener-class>3  </listener>

7.Servlet Configuration

1 <servlet> 2    <servlet-name>servlet name </servlet-name> 3    <servlet-class>servlet class full path </servlet-class> 4    <init-param> 5        <param-name> parameter name </param-name> 6        < Param-value> parameter Values </param-value> 7    </init-param> 8    <run-as> 9        <description> Security role for anonymous access</description>10        <role-name>tomcat</role-name>11    </ RUN-AS>12 <load-on-startup> Specifies the order in which the servlet is loaded when the Web App starts </load-on-startup>13 </servlet>14 < servlet-mapping>15   <servlet-name>servlet name </servlet-name>16   <url-pattern> mapping path </url-pattern>17 </servlet-mapping>

8. Session Timeout configuration (in minutes)

1 <session-config>2      <session-timeout>120</session-timeout>3  </session-config>

9.MIME type Configuration

1 <mime-mapping>2      <extension>htm</extension>3      <mime-type>text/html</ Mime-type>4  </mime-mapping>

10. Specify the Welcome File page Configuration

1  <welcome-file-list>2      <welcome-file>index.jsp</welcome-file>3      <welcome-file >index.html</welcome-file>4      <welcome-file>index.htm</welcome-file>5  </ Welcome-file-list>

11. Configuration Error Page

(1). Configure Error-page with error codes

1 <!--configured to jump to the error handling page notfound.jsp-->2 <error-page>3 <error-code>404</when a 404 error occurs on the system       Error-code>4       <location>/notfound.jsp</location>5  </error-page>

(2). Configure Error-page by type of exception

1 <!--configured to jump to error handling page when System java.lang.NullException (that is, null pointer exception) ERROR.JSP-->2 <error-page>3       < Exception-type>java.lang.nullexception</exception-type>4       <location>/error.jsp</location >5 </error-page>

12.TLD Configuration

1 <taglib>2      <taglib-uri>http://jakarta.apache.org/tomcat/debug-taglib</taglib-uri>3      <taglib-location>/web-inf/jsp/debug-taglib.tld</taglib-location>4  </taglib>

If the development tool has been an error, you should put <taglib> into <jsp-config>

1 <jsp-config>2      <taglib>3          <taglib-uri>http://jakarta.apache.org/tomcat/debug-taglib </taglib-uri>4          <taglib-location>/web-inf/pager-taglib.tld</taglib-location>5      </ Taglib>6  </jsp-config>

13. Resource Management Object Configuration

1 <resource-env-ref>2      <resource-env-ref-name>jms/stockqueue</resource-env-ref-name>3  </resource-env-ref>

14. Resource Factory Configuration

1 <resource-ref>2      <res-ref-name>mail/session</res-ref-name>3      <res-type> Javax.mail.session</res-type>4      <res-auth>container</res-auth>5 </resource-ref>

Configure the database connection pool where you can configure

1  <resource-ref>2      <description>jndi JDBC DataSource of shop</description>3      < Res-ref-name>jdbc/sample_db</res-ref-name>4      <res-type>javax.sql.DataSource</res-type> 5      <res-auth>container</res-auth>6  </resource-ref>

15. Security Restriction Configuration

1 <security-constraint> 2      <display-name>example Security constraint</display-name> 3      < Web-resource-collection> 4          <web-resource-name>protected area</web-resource-name> 5          < Url-pattern>/jsp/security/protected/*</url-pattern> 6          

16. Login Verification Configuration

1  <login-config>2      <auth-method>form</auth-method>3      <realm-name> example-based authentiation area</realm-name>4      <form-login-config>5          <form-login-page>/ Jsp/security/protected/login.jsp</form-login-page>6          <form-error-page>/jsp/security/protected/ Error.jsp</form-error-page>7      </form-login-config>8  </login-config>

17. Security role: The Security-role element gives a list of security roles that will appear in the Role-name child elements of the security-role-ref element within the servlet element.
Declaring roles separately makes it easier for advanced Ides to handle security information.

1 <security-role>2      <role-name>tomcat</role-name>3  </security-role>

18.Web environment parameter: env-entry element declares environment item for web App

1 <env-entry>2      <env-entry-name>minexemptions</env-entry-name>3      <env-entry-value >1</env-entry-value>4      <env-entry-type>java.lang.integer</env-entry-type>5 </ Env-entry>

19.EJB Declaration

1 <ejb-ref>2      <description>example ejb reference</decription>3      <ejb-ref-name>ejb/ Account</ejb-ref-name>4      <ejb-ref-type>entity</ejb-ref-type>5      

20. Local EJB Declaration

1  <ejb-local-ref>2      <description>example loacal ejb reference</decription>3      < Ejb-ref-name>ejb/processorder</ejb-ref-name>4      <ejb-ref-type>session</ejb-ref-type>5      <local-home>com.mycompany.mypackage.processorderhome</local-home>6      <local> Com.mycompany.mypackage.processorder</local>7  </ejb-local-ref>

Iii. Summary

The above is commonly used in the configuration of Web. XML and the role of the elements, welcome to raise objections and inappropriate places to learn together.

The most complete Web. XML configuration file element in history

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.