Detailed description of the web. xml configuration file

Source: Internet
Author: User
Tags configuration settings tld

WebIntroduction to. XML elements

Each siteWeb-INFWeb. Xml configuration file, which provides the configuration settings for 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 moreWebThe Set Value of. xml must understand its schema.WebIn. XML, we know that its schema is customized by sum Microsystems. If you want to know more about it,

Can go to http://java.sun.com/xml/ns/j2ee/Web-Mapp_2_4.xsd web page, which provides more details. 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 child elements: Small-icon and large-icon.WebPath of small icons and big icons on the platform.

<Small-Icon>/path/smallicon.gif </small-Icon>

The small-Icon element should pointWebThe path of a small icon in the 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 pointWebThe path of a large chart in the platform 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 specify whether the platform can be processed in a distributed manner. IfWebThis element appears in. XML, which indicates that the platform has been

It is designed to be executed discretely among multiple JSP containers.

Example:

<Distributable/>

<Context-param>

___________________________________


the context-Param element is used to set the environment parameters (context) of the Web platform), it contains two sub-elements:
param-name And param-value.
parameter name
set the context name

set the value of context name

example:

param_name
param_value

this parameter is set, you can use the following methods in the JSP webpage:

$ {initparam. param_name}
you can use the following methods to obtain the parameter in servlet:
string param_name = getservletcontext (). getinitparamter ("param_name");


_____________________________
the filter element is used to declare filter settings. in addition to the sub-elements described below, the filter element also includes introduced ,
, , , which is used in the same way.
Filter Name
defines the Filter Name.
filter class name
defines the name of the filter class. example: COM. foo. hello

example:

setcharacterencoding
coreservlet. javaworld. ch11.setcharacterencodingfilter

encoding

gb2312

<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>


_______________________________________

the listener element is used to define the listener interface, its main sub-element is
Class Name of listener
define listener class Name. example: COM. foo. hello

example:

coreservlet. javaworld. ch11.contenxtlistener


_____________________________________________
the servlet-mapping element contains two child elements: servlet-Name and URL-pattern. defines the URL of the servlet.
servlet name
define the servlet name.
servlet URL
defines the rul of the servlet. example: /servlet/Hello

example:

loginchecker
/loginchecker


______________________________

session-config contains a sub-element session -Timeout. define the session parameter in the Web platform.
minute
define the Web Platform the validity period of all sessions. the Unit is minute.

example:

20


_______________________________________________

mime-mapping contains two sub-elements Extension and mime-type. defines a certain extension and a mime type for ing.
extension name
extension name
MIME format
MIME format.

example:

doc
application/vnd. MS-word

XLS
application/vnd. MS-Excel

PPT
application/vnd. MS-PowerPoint


_________________________________________________

welcome-file- list contains a child element welcome-file. used to define the homepage columns.
is used to specify the name of the home page file
welcome-file is used to specify the name of the home page file. we can use to specify several home pages, and the server will find the home pages in the set order.
example:

index. JSP
index.htm


_____________________

the error-page element contains three child elements. error-code, exception-type and location. Code (Error Code) or exception)
to Web .
Error Code
HTTP Error code, for example: 404
exception
JAVA exception type with the full name
/path
related resource paths on the Web platform
/error-page>
example:

404
/error404.jsp

JAVA. lang. exception
/condition T. JSP

<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>

TLD FileWebThe storage location of the 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>

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.