Common web. XML elements
<Web-app>
<Display-Name> </display-Name> defines the web application name.
<Description> </description> declares the web application description.
<Context-param> </context-param> the context-Param element declares the initialization parameters in the application scope.
<Filter> </filter> the filter element associates a name with a class that implements the javax. servlet. Filter interface.
<Filter-mapping> </filter-mapping> once a filter is named, the filter-mapping element is used to associate it with one or more servlet or JSP pages.
<Listener> </listener> servlet API Version 2.3 adds support for event listening programs. The event listening program is notified when a session is created, modified, or deleted.
The listener element specifies the event listener class.
<Servlet> </servlet> when initializing parameters or custom URLs to the servlet or JSP page, you must first name the servlet or JSP page. The servlet element is used to complete this task.
<Servlet-mapping> </servlet-mapping> the server generally provides the servlet with a default URL: http: // host/webappprefix/servlet/servletname.
However, this URL is often changed so that the servlet can access initialization parameters or process relative URLs more easily. When you change the default URL, use the servlet-mapping element.
<Session-config> </session-config> If a session is not accessed for a certain period of time, the server can discard it to save memory.
You can use the setmaxinactiveinterval method of httpsession to explicitly set the timeout value for a single session object, or use the session-config element to specify the default timeout value.
<Mime-mapping> </mime-mapping> If a web application wants to assign a specific MIME type to a special file, the mime-mapping element provides this guarantee.
<Welcome-file-List> </welcome-file-List> indicates the file used by the server when the server receives a URL that references a directory name rather than a file name.
<Error-page> </error-page> You can specify the page to be displayed when a specific HTTP status code is returned or an exception of a specific type is thrown.
<Taglib> </taglib> specifies an alias for the tag library descriptor file (TAG libraryu descriptor file. This feature enables you to change the location of TLD files,
Instead of editing the JSP pages that use these files.
<Resource-env-ref> </resource-env-ref> declares a resource-related management object.
<Resource-ref> </resource-ref> declares the external resources used by a resource factory.
<Security-constraint> </security-constraint> specifies the URL to be protected. It is used together with the login-config element.
<Login-config> </login-config> specifies how the server grants permissions to users attempting to access protected pages. It is used with the sercurity-constraint element.
<Security-role> </security-role> provides a list of security roles that appear in the security-role-ref element of the servlet element.
In the role-name sub-element. Declaring roles separately makes it easier for advanced ide to process security information.
<Env-entry> </env-entry> declares the environment items of the Web application.
<EJB-ref> </EJB-ref> declares the reference of the main directory of an EJB.
<EJB-local-ref> </EJB-local-ref> declares the application of the local main directory of an EJB.
</Web-app>
Element configuration
1. Web application icons: The IDE and GUI tools are used to indicate the large and small icons of Web applications.
<Icon>
<Small-Icon>/images/app_small.gif </small-Icon>
<Large-Icon>/images/app_large.gif </large-Icon>
</Icon>
2. Web Application name: a GUI tool provided may be used to mark a name of a specific web application.
<Display-Name> Tomcat Example </display-Name>
3. Web application Description: This descriptive text is provided.
<Disciption> Tomcat Example servlets and JSP pages. </disciption>
4. context parameters: declare the initialization parameters within the application scope.
<Context-param>
<Param-Name> contextparameter </para-Name>
<Param-value> test </param-value>
<Description> it is a test parameter. </description>
</Context-param>
In the servlet, you can use getservletcontext (). getinitparameter ("context/Param") to obtain
5. filter configuration: associate a name with a class that implements the javaxs. servlet. Filter interface.
<Filter>
<Filter-Name> setcharacterencoding </filter-Name>
<Filter-class> com. mytest. setcharacterencodingfiltEr </filter-class>
<Init-param>
<Param-Name> encoding </param-Name>
<Param-value> gb2312 </param-value>
</Init-param>
</Filter>
<Filter-mapping>
<Filter-Name> setcharacterencoding </filter-Name>
<URL-pattern>/* </url-pattern>
</Filter-mapping>
6. Listener Configuration
<Listener>
<Listerner-class> listener. sessionlistener </listener-class>
</Listener>
7. servlet Configuration
Basic Configuration
<Servlet>
<Servlet-Name> Snoop </servlet-Name>
<Servlet-class> snoopservlet </servlet-class>
</Servlet>
<Servlet-mapping>
<Servlet-Name> Snoop </servlet-Name>
<URL-pattern>/snoop </url-pattern>
</Servlet-mapping>
Advanced Configuration
<Servlet>
<Servlet-Name> Snoop </servlet-Name>
<Servlet-class> snoopservlet </servlet-class>
<Init-param>
<Param-Name> Foo </param-Name>
<Param-value> bar </param-value>
</Init-param>
<Run-as>
<Description> security role for anonymous access </description>
<Role-Name> Tomcat </role-Name>
</Run-as>
</Servlet>
<Servlet-mapping>
<Servlet-Name> Snoop </servlet-Name>
<URL-pattern>/snoop </url-pattern>
</Servlet-mapping>
Element description
<Servlet> </servlet> is used to declare the data of a servlet, mainly including the following sub-elements:
<Servlet-Name> </servlet-Name> specifies the servlet name.
<Servlet-class> </servlet-class> specifies the servlet class name.
<JSP-File> </JSP-File> specifies the complete path of a JSP page on the web platform.
<Init-param> </init-param> is used to define parameters. Multiple init-Param parameters are allowed. Access the initialization parameters through the getinitparamenter (string name) method in the servlet class.
<Load-on-startup> </load-on-startup> specifies the servlet loading sequence when the web application starts.
When the value is positive or zero: The servlet container first loads the servlet with a small value, and then loads the servlet with a large value in sequence.