Understanding of labels in Web. xml files

Source: Internet
Author: User
Tags configuration settings tld

Each station's WEB-INF has a web. xml setting file, which provides the configuration settings of our platform.

Web. XML definition:
. Platform Name and description
. Initialize environment parameters (context)
. Servlet name and ing
. Session settings
. Tag library ing
. JSP web page settings
. Mime Type Processing
. Handle errors
. Use jdni to obtain platform Resources

To learn more about web. the Set Value of XML. You must understand its schema from the web. XML knows that its schema is customized by sum Microsystems. If you want to learn more about it,
You can go to the http://java.sun.com/xml/ns/j2ee/web-mapp_2_4.xsdnet page for more detailed introduction. Here I will introduce what we usually see most.

<? XML version = "1.0" encoding = "ISO-8859-1"?>

<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 statement made when writing XML, defines the XML version, encoding format, and important to specify the source of schema, for the http://java.sun.com/xml/ns/j2ee
/Web-app_2_4.xsd.


<Description>, <display-Name>, <icon>
____________________________________________

<Description> platform description </discription>
Describe the platform.

<Display-Name> platform name </display-Name>
Define the platform name.

<Icon>
The icon element contains two sub-elements: Small-icon and large-icon. It is used to specify the paths of 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 platform. The size is 16x16 pixel, but the image file must be in GIF or JPEG format. 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 on the web platform. The size is 32x32 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>
<Description> JSPs 2.0 Tech Book's examples </description>
<Icon>
<Small-Icon>/images/small.gif </small-Icon>
<Large-Icon>/images/large. gir </large-Icon>
</Icon>


<Distributable>
______________________________________

<Distributable>
The distributable element is an empty tag. Whether the distributable element exists or not can be used for distributed processing on the platform. If this element is displayed in Web. XML, it indicates that the platform has been
It is designed to be executed discretely among multiple JSP containers.
Example:
<Distributable/>

 

<Context-param>
___________________________________

<Context-param>
The context-Param element is used to set the context of the Web platform. It contains two child elements:
Param-name And param-value.
<Param-Name> parameter name </param-Name>
Set context name
<Param-value> value </param-value>
Set the value of context name
</Context-param>
Example:
<Context-param>
<Param-Name> param_name </param-Name>
<Param-value> param_value </param-value>
</Context-param>
The parameters set here can be obtained in the JSP webpage using the following methods:
$ {Initparam. param_name}
You can use the following methods in servlet:
String param_name = getservletcontext (). getinitparamter ("param_name ");

 

<Filter>
_________________________________
The filter element is used to declare related settings of the filter. In addition to the sub-elements described below, the filter element also includes <servlet> introduced <icon>, <display-Name>
, <Description>, <init-param>, which has the same purpose.
<Filter-Name> Filter Name </filter-Name>
Define the Filter Name.
<Filter-class> filter class name </filter-class>
Define the name of the filter class. 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>


<Filter-mapping>
______________________________________
<Filter-mapping>
Filter-Name and URL-pattern are two main child elements of the filter-mapping element. They are used to define the URL corresponding to the filter.
<Filter-Name> Filter Name </filter-Name>
Define the Filter Name.
<URL-pattern> URL </url-pattern>
The RUL of the filter. For example: <URL-pattern>/filter/Hello </url-pattern>

<Servlet-Name> servlet name <servlet-Name>
Defines the servlet name.
<Dispatcher> request | include | forward | error </disaptcher>
Set the request method corresponding to the filter, including rquest, include, forwar, and error. The default value is request.
</Filter-mapping>
Example:
<Filter-mapping>
<Filter-Name> gzipencoding </filter-Name>
<URL-pattern>/* </url-pattern>
</Filter-mapping>

 

<Listener>
___________________________________________
<Listener>
The listener element is used to define the listener interface. Its main sub-element is <listener-class>
<Listen-class> Class Name of listener </listener-class>
Class Name defining listener. Example: COM. Foo. Hello
<Listener>
Example:
<Listener>
<Listener-class> coreservlet. javaworld. ch11.contenxtlistener </listener-class>
</Listener>

 

<Servlet-mapping>
_____________________________________________
The servlet-mapping element contains two child elements: servlet-Name and URL-pattern, which are used to define the URL of the servlet.
<Servlet-Name> servlet name </servlet-Name>
Defines the servlet name.
<URL-pattern> servlet URL </url-pattern>
Define the rul of the servlet. 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>


<Session-cofing>
__________________________________
<Session-config>
Session-config contains a sub-element session-Timeout. It defines the session parameter in the Web platform.
<Session-Timeout> minute </session-Timeout>
Defines the validity period of all sessions on the web platform. The unit is minute.
</Session-config>
Example:
<Session-config>
<Session-Timeout> 20 </session-Timeout>
</Session-config>


<Mime-mapping>
___________________________________________________
<Mima-mapping>
Mime-mapping contains two child elements: Extension and mime-type. Define a certain extension and a mime type to be mapped.
<Extension> name of the extension </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>


<Welcome-file-List>
_____________________________________________
<Welcome-file-List>
Welcome-file-list contains a sub-element welcome-file. It is used to define the homepage columns.
<Welcome-File> specifies the name of the home page file. </welcome-flie>
Welcome-file is used to specify the name of the home page file. We can use <welcome-File> to specify several home pages, and the server will find the home page in the set order.
Example:
<Welcome-file-List>
<Welcome-File> index. jsp </welcome-File>
<Welcome-File> index.htm </welcome-File>
</Welcome-file-List>

 

<Error-page>
_________________________
<Error-page>
The error-page element contains three sub-elements: Error-code, exception-type, and location. corresponds to the error code or exception type.
The path to the web platform resource.
<Error-code> Error Code </error-code>
HTTP Error Code, for example, 404
<Exception-type> exception </exception-type>
Java exception type with a complete name
<Location>/path </location>
Related resource path on 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>/snapshot T. jsp </location>
</Error-page>

 

<JSP-config>
_______________________________________________
<JSP-config>
The JSP-config element is mainly used to set JSP-related configurations. <JSP: config> includes two sub-elements: <taglib> and <JSP-property-group>. The <taglib> element
JSP 1.2 already exists, and <JSP-property-group> is a new element of JSP 2.0.

<Taglib>
The taglib element contains two sub-elements: taglib-Uri and taglib-location. It is used to set the tag library path used for JSP web pages.
<Taglib-Uri> URI </taglib-Uri>
The taglib-Uri defines the URI of the TLD file. The taglib command of the JSP webpage can access the TLD file through this URI.
<Taglib-location>/WEB-INF/lib/xxx. TLD </taglib-laction>
The storage location of the TLD file corresponding to the Web platform.
</Taglib>

<JSP-property-group>
The JSP-property-group element contains eight elements:
<Description> description </descrition>
Description of this setting

<Display-Name> name </display-Name>
The specified name.

<URL-pattern> URL </url-pattern>
Set the range affected by the value, such as/CH2 or/*. jsp.

<El-ignored> true | false </El-ignored>
If true, El syntax is not supported.

<Scripting-invalid> true | false </Scripting-invalid>
If it is true, the <% region %> syntax is not supported.

<Page-encoding> encoding </page-encoding>
Sets the encoding of JSP web pages.

<Include-prelude>. jspf </include-prelude>
Set the JSP page header with the extension. jspf

<Include-coda>. jspf </include-coda>
Set the end of the JSP webpage 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>

 

<Resource-ref>
________________________________________________
<Resource-ref>
The resource-ref element includes five sub-elements: Description, res-ref-name, res-type, res-auth, and res-sharing-scope. The site can be obtained using JNDI.
Use resources.
<Description> description </description>
Resource Description

<Rec-ref-Name> Resource Name </REC-ref-Name>
Resource Name

<Res-type> Resource Type </RES-type>
Resource Type

<Res-auth> application | container </RES-auth>
Resources are licensed by application or container.

<Res-sharing-scope> retriable | unretriable </RES-sharing-scope>
Whether resources can be shared. The default value is retriable.
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>

These are some more commonly used, detailed can log on: http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd

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.