9web XML Elements

Source: Internet
Author: User

Web. XML Common Elements
<web-app>
<display-name></display-name>
Defines the name of the Web App


<description></description>
Declaring a web app's descriptive information

<context-param></context-param>
The Context-param element declares an application-scoped initialization parameter.

<filter></filter>
The filter element will have a name and an implementation
<a href= "http://www.cnblogs.com/bukudekong/archive/2011/12/26/2302183.html" >javax.servlet.filter</a The class of the > interface is associated.


<filter-mapping></filter-mapping>
Once a filter is named, it should be associated with one or more servlet or JSP pages using the filter-mapping element.

<listener></listener>
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 the event listener class.

<servlet></servlet>
When you set initialization parameters or custom URLs to a servlet or JSP page, you must first name the servlet or JSP page. The servlet element is used to accomplish this task.


<servlet-mapping></servlet-mapping>
The server typically provides a default URL for the servlet:
Http://host/webAppPrefix/servlet/ServletName.

<span style= "color: #008000;" >
However, this URL is often changed so that the servlet can access the initialization parameters or make it easier to handle relative URLs. </span> Use the servlet-mapping element when changing the default URL.

<session-config></session-config>
If a session is not 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 Setmaxinactiveinterval method of HttpSession, or you can use the Session-config element to make a default timeout.

<mime-mapping></mime-mapping>
The mime-mapping element provides this assurance if the Web app has a particular file to think about and wants to ensure that they are assigned a specific MIME type.

<welcome-file-list></welcome-file-list>
Indicates which file the server uses when it receives a URL that references a directory name instead of a file name.

<error-page></error-page> can make a page that will be displayed when a specific HTTP status code is returned, or when a particular type of exception is thrown.
<taglib></taglib>
Specifies an alias for the tag Library descriptor file (tag Libraryu descriptor files). This feature enables you to change the location of the TLD file,
Instead of editing JSP pages that use these files.


<resource-env-ref></resource-env-ref>
Declares a management object that is associated with a resource.

<resource-ref></resource-ref>
Declares an external resource used by a resource factory.

<security-constraint></security-constraint>
Develop URLs that should be protected. It is used in conjunction with the Login-config element


<login-config></login-config>
Specifies how the server should authorize users attempting to access a protected page. It is used in conjunction with the Sercurity-constraint element.

<security-role></security-role>
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.

<env-entry></env-entry>
Declares the environment item for the web App.


<ejb-ref></ejb-ref>
Declares a reference to the home directory of an EJB.


<ejb-local-ref></ejb-local-ref>
Declares an application for the local home directory of an EJB.
</web-app>






















Web. XML element Introduction
The web-inf of each station has a config file for Web. XML, which provides the configuration settings for our platform.
1.<?xml version= "1.0" encoding= "Iso-8859-1"?>
The deployment descriptor file, like all XML files, must start with an XML header. This header declares the XML version that can be used and gives the character encoding of the file.
2.<web-app 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/web-app_2_4.xsd"
version= "2.4" >
<web-app>
This is a general declaration made when writing XML, defining the version of the XML, the encoding format, and the important source of the specified schema for http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd.
3.<description> Platform Description </discription> description of the platform.
4.<display-name> platform name </display-name> define the name of the platform.
The <icon>icon element contains the Small-icon and Large-icon two child elements. Used to specify the path to small icons and large icons on the Web platform.
<small-icon>/Path/smallicon.gif</small-icon>
The Small-icon element should point to the path of a small icon in the Web site, with a size of X pixel, but the image file must be in GIF or JPEG format, with the extension must be:. gif or. jpg.
<large-icon>/Path/largeicon-jpg</large-icon>
The Large-icon element should point to a large chart path in the Web site, with a size of X-pixel, but the image file must be in GIF or JPEG format and the extension must be; GIF or JPG.
Example:
<display-name>develop example</display-name>
&LT;DESCRIPTION&GT;JSP 2.0 Tech book ' s examples</description>
<icon>
<small-icon>/images/small.gif</small-icon>
<large-icon>/images/large.gir</large-icon>
</icon>
5.<distributable>
The distributable element is an empty label, and its presence or absence can specify whether the platform is distributed. If this element appears in Web. XML, the platform is
is designed to be distributed across multiple JSP Container.
Example:
6.<context-param>
The Context-param element is used to set the environment parameter (context) of the Web platform, which contains two child elements:
Param-name and Param-value.
<param-name> Parameter name </param-name>
Set the context name
<param-value> Values </param-value>
Set the value of the context name
</context-param>
Example:
<context-param>
<param-name>param_name</param-name>
<param-value>param_value</param-value>
</context-param>
The parameters that are set in the JSP Web page can be obtained using the following methods:
${initparam.param_name}
If the servlet can use the following methods to obtain:
String Param_name=getservletcontext (). Getinitparamter ("Param_name");
7.<filter>
The filter element is used to declare the relevant settings for the filter. The filter element includes, in addition to the child elements described below, <servlet> introduced <icon>,<display-name>
, <description>,<init-param> it uses the same.
Name of <filter-name>filter </filter-name>
Defines the name of the filter.
Class name of <filter-class>filter </filter-class>
Defines the class name of the filter. For example: Com.foo.hello
</filter>
Example:
<filter>
<filter-name>setCharacterEncoding</filter-name>
<filter-class>coreservlet.javaworld.CH11.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GB2312</param-value>
</init-param>
</filter>
8.<filter-mapping>
<filter-mapping>
The two main child elements of the filter-mapping element Filter-name and Url-pattern. Used to define the URL to which the filter corresponds.
Name of <filter-name>filter </filter-name>
Defines the name of the filter.
<url-pattern>URL</url-pattern>
The rul corresponding to Filter. For example:<url-pattern>/filter/hello</url-pattern>
Name of 9.<servlet-name>servlet <servlet-name>
Defines the name of the servlet.
<dispatcher>request| include| forward| Error</disaptcher>
Set the filter corresponding request method, there are rquest,include,forwar,error four kinds, the default is request.
</filter-mapping>
Example:
<filter-mapping>
<filter-name>GZIPEncoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
10.<listener>
The listener element is used to define the listener interface, and its primary child element is <listener-class>
Class name of <listen-class>listener </listener-class>
Defines the class name for the listener. For example: Com.foo.hello
<listener>
Example:
<listener>
<listener-class>coreservlet.javaworld.CH11.ContenxtListener</listener-class>
</listener>
11.<servlet-mapping>
The servlet-mapping element contains two child elements servlet-name and url-pattern. Used to define the URL of the servlet.
Name of <servlet-name>servlet </servlet-name>
Defines the name of the servlet.
<url-pattern>servlet url</url-pattern>
Defines the rul that the Servlet corresponds to. For example:<url-pattern>/servlet/hello</url-pattern>
</servlet-mapping>
Example:
<servlet-mapping>
<servlet-name>LoginChecker</servlet-name>
<url-pattern>/LoginChecker</url-pattern>
</servlet-mapping>
12.<session-cofing>
The session-config contains a child element, Session-timeout. Defines the session parameter in the Web platform.
<session-timeout> minutes </session-timeout>
Defines the expiration date for all sessions of this web site. Units are minutes.
</session-config>
Example:
<session-config>
<session-timeout>20</session-timeout>
</session-config>
13.<mime-mapping>
The mime-mapping contains two child elements extension and Mime-type. Defines an extension and a MIME type to be mapped.
<extension> extension name </extension>
Extension name
<mime-type>mime format </mime-type>
MIME format.
</mime-mapping>
Example:
<mime-mapping>
<extension>doc</extension>
<mime-type>application/vnd.ms-word</mime-type>
</mime-mapping>
<mime-mapping>
<extension>xls</extension>
<mime-type>application/vnd.ms-excel</mime-type>
</mime-mapping>
<mime-mapping>
<extension>ppt</extesnion>
<mime-type>application/vnd.ms-powerpoint</mime-type>
</mime-mapping>
14.<welcome-file-list>
The welcome-file-list contains a child element, welcome-file. Used to define the first page of the list.
<welcome-file> used to specify the home page file name </welcome-flie>
Welcome-file is used to specify the home page file name. We can use <welcome-file> to specify a few home pages, and the server will be in accordance with the set order to find the homepage.
Example:
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.htm</welcome-file>
</welcome-file-list>
15.<error-page>
The Error-page element contains three child elements, Error-code,exception-type, and location. Corresponds to the type of error code or exception (exception)
To the Web platform resource path.
<error-code> Error Codes </error-code>
HTTP Error Code, for example: 404
<exception-type>Exception</exception-type>
A full-name Java exception type
<location>/Path </location>
Related resource paths within the Web platform
</error-page>
Example:
<error-page>
<error-code>404</error-code>
<location>/error404.jsp</location>
</error-page>
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/except.jsp</location>
</error-page>
16.<jsp-config>
The Jsp-config element is primarily used to set the relevant configuration of the JSP,<jsp:config> including <taglib> and <jsp-property-group> two sub-elements. Where <taglib> The element already exists at JSP 1.2, and <jsp-property-group> is the new element in JSP 2.0.
<taglib>
The Taglib element contains two child elements Taglib-uri and taglib-location. Used to set the tag library path used by the JSP Web page.
<taglib-uri>URI</taglib-uri>
Taglib-uri the taglib directive of the URI,JSP Web page that defines the TLD file can be accessed through this URI to the TLD file.
<taglib-location>/WEB-INF/lib/xxx.tld</taglib-laction>
The TLD file corresponds to the location where the Web site is stored.
</taglib>
<jsp-property-group>
The Jsp-property-group element contains 8 elements, respectively:
<description>Description</descrition>
Description of this setting
<display-name>Name</display-name>
The name of this setting
<url-pattern>URL</url-pattern>
The range affected by the setpoint, such as:/ch2 or/*.jsp
<el-ignored>true|false</el-ignored>
True to indicate that El syntax is not supported.
<scripting-invalid>true|false</scripting-invalid>
True indicates that the <%scription%> syntax is not supported.
17.<page-encoding>encoding</page-encoding>
Set the encoding of the JSP Web page
18.<include-prelude>.jspf</include-prelude>
Sets the header of the JSP Web page with the extension. JSPF
JSP segments (formerly known as JSP fragments) JSPF files are incomplete JSPs and are used by other JSPs for inclusion.
19.<include-coda>.jspf</include-coda>
Sets the end of the JSP Web page with the extension. JSPF
</jsp-property-group>
</jsp-config>
Example:
<jsp-config>
<taglib>
<taglib-uri>Taglib</taglib-uri>
<taglib-location>/WEB-INF/tlds/MyTaglib.tld</taglib-location>
</taglib>
<jsp-property-group>
<description>
Special Property Group for JSP Configuration JSP example.
</description>
<display-name>JSPConfiguration</display-name>
<uri-pattern>/*</uri-pattern>
<el-ignored>true</el-ignored>
<page-encoding>GB2312</page-encoding>
<scripting-inivalid>true</scripting-inivalid>
............
</jsp-property-group>
</jsp-config>
20.<resource-ref>
The Resource-ref element consists of five child element Description,res-ref-name,res-type,res-auth,res-sharing-scope. Use Jndi to get a platform
Leverage resources.
<description> Description </description>
Resource Description
<rec-ref-name> Resource Name </rec-ref-name>
Resource Name
<res-type> Resources Category </res-type>
Types of resources
<res-auth>application| Container</res-auth>
Resources are licensed by application or container
<res-sharing-scope>shareable| Unshareable</res-sharing-scope>
Whether the resource can be shared. Default value is shareable
Example:
<resource-ref>
<description>jndi JDBC DataSource of jspbook</description>
<res-ref-name>jdbc/sample_db</res-ref-name>
<res-type>javax.sql.DataSoruce</res-type>
<res-auth>Container</res-auth>
</resource-ref>

9web XML Elements

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.