Understand xml configuration

Source: Internet
Author: User

Parse web. xml

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <web-app xmlns = "http://java.sun.com/xml/ns/j2ee"> <br/> <display-Name> KPI engine </display-Name> <! -- <Br/> <welcome-file-List> <br/> <welcome-File> welcome. JSP </welcome-File> <br/> </welcome-file-List> </P> <p> --> <servlet> <br/> <servlet-Name> action </servlet-Name> <br/> <servlet-class> Org. apache. struts. action. actionservlet </servlet-class> <br/> <init-param> <br/> <param-Name> config </param-Name> <br/> <param-Value >/WEB-INF/CONF/struts-config.xml </param-value> <br/> </init-param> <br/> <load-on-startup> 2 </load-on-startup> <br/> </servlet> </P> <p> <servlet> <br/> <servlet-Name> internetserlet </ servlet-Name> <br/> <servlet-class> <br/> COM. inspur. kpiengine. smssend. action. internetserlet <br/> </servlet-class> <br/> <load-on-startup> 1 </load-on-startup> <br/> </servlet> </P> <p> <servlet-mapping> <br/> <servlet-Name> action </servlet-Name> <br/> <URL-pattern> *. DO </url-pattern> <br/> </servlet-mapping> <br/> <Servlet-mapping> <br/> <servlet-Name> internetserlet </servlet-Name> <br/> <URL-pattern>/servlet/internetserlet </url-pattern> <br/> </servlet-mapping> </P> <p> <! -- <Filter> <br/> <filter-Name> Security filter </filter-Name> <br/> <filter-class> <br/> Org. securityfilter. filter. securityfilter <br/> </filter-class> <br/> <init-param> <br/> <param-Name> config </param-Name> <br/> <param-value> <br/>/WEB-INF/CONF/securityfilter-config.xml <br/> </param-value> </P> <p> </init-param> <br /> <init-param> <br/> <param-Name> validate </param-Name> <br/> <param-value> false </param-value> <B R/> </init-param> <br/> </filter> </P> <p> <filter-mapping> <br/> <filter-Name> Security Filter </filter-Name> <br/> <URL-pattern>/* </url-pattern> <br/> </filter-mapping> <br/> --> <br/> <session-config> <br/> <session-Timeout> 100 </session-Timeout> <br/> </session-config> </P> <p> <JSP-config> <br/> <taglib-Uri>/WEB-INF/struts-bean.tld </taglib-Uri> <br/> <taglib-location >/WEB-INF/TLD/struts-bean.tld </ Taglib-location> <br/> </taglib> <br/> <taglib-Uri>/WEB-INF/struts-html.tld </taglib-Uri> <br /> <taglib-location>/WEB-INF/TLD/struts-html.tld </taglib-location> <br/> </taglib> <br/> <taglib -Uri>/WEB-INF/struts-logic.tld </taglib-Uri> <br/> <taglib-location>/WEB-INF/TLD/struts-logic.tld </taglib-location> <br/> </ taglib> <br/> <taglib-Uri>/WEB-INF/struts-nested.tld </T Aglib-Uri> <br/> <taglib-location> <br/>/WEB-INF/TLD/struts-nested.tld <br/> </taglib-location> <br/> </taglib> <br/> <taglib-Uri>/WEB-INF/struts-tiles.tld </taglib-Uri> <br/> <taglib-location>/WEB-INF/TLD /struts-tiles.tld </taglib-location> <br/> </taglib> <br/> <taglib-Uri> http://java.sun.com/jstl/core </taglib-Uri> <br/> <taglib-location>/WEB-INF/TLD/C. TLD </taglib-location> <br /> </Taglib> <br/> <taglib-Uri> http://java.sun.com/jstl/core_rt </taglib-Uri> <br/> <taglib-location>/WEB-INF /TLD/c-rt.tld </taglib-location> <br/> </taglib> <br/> </JSP-config> <br/> <context-param> <br/> <param-Name> weblogic. httpd. inputcharset. /* </param-Name> <br/> <param-value> GBK </param-value> <br/> </context-param> <br/> <! -- Spring configuration files to be loaded for each module --> <br/> <! -- <Context-param> <br/> <param-Name> contextconfiglocation </param-Name> <br/> <param-value>/WEB-INF/CONF/bean-config.xml </Param -value> <br/> </context-param> <br/> <listener-class> Org. springframework. web. context. contextloaderlistener </listener-class> <br/> </listener> </P> <p> --> <mime-mapping> <br/> <extension> HTM </Extension> <br/> <mime-type> text/html; charset = UTF-8 </mime-type> <br/> </mime-mapping> <br/> <extension> HTML </extension> <br/> <mime-type> text/html; charset = GBK </mime-type> <br/> </mime-mapping> </P> <p> </Web-app> <br/>

 

The top-level (Root) element of all deployment descriptor files is: Web-app

The display-name element provides a GUI tool that may be used to mark the name of a specific web application.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~

The description Description element provides descriptive text related to this.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~

The filter element associates a name with a class that implements the javax. servlet. Filter interface.
Once the filter-mapping name is a filter, use the filter-mapping element to associate it with one or more servlet or JSP pages.

 

------------------------------ Once a filter is created, the filter element, filter-Name (any name), and ),

File-class (fully qualified class name) and (optional) Init-Params sub-element declare it.

Note that the order in which elements appear in Web. XML Web-app elements is not arbitrary;

The Order required by the server (but not required) is allowed, and some servers actually do the same.

Note that all filter elements must appear before any filter-mapping element,

The filter-mapping element must appear before all servlet or servlet-mapping elements.
For example, given the reportfilter class, you can make the following filter declaration in Web. xml.

It associates the name reporter with the actual class reportfilter (located in the moreservlets package.

<Filter>
<Filter-Name> reporter </filter-Name>
<Filter-class> moresevlets. reportfilter </filter-class>
</Filter>

Once a filter is named, you can use the filter-mapping element to associate it with one or more servlet or JSP pages.

There are two options for this job.

First, you can use the filter-Name and servlet-name sub-elements to match the filter with a specific servlet name.

(This servlet name must be later declared using the servlet element in the same web. xml file) associated.

For example, the following program snippet indicates that the system only needs to use a custom URL.

Access the servlet or JSP page named someservletname and run the filter named reporter.

<Filter-mapping>
<Filter-Name> reporter </filter-Name>
<Servlet-Name> someservletname </servlet-Name>
</Filter-mapping>

Second, you can use the filter-Name and URL-pattern sub-elements to match the filter with a group of servlet,

JSP pages or static content are associated. For example, the program fragment in the photo shows that the system only needs to access any URL in the Web application,

Run the filter named reporter.

<Filter-mapping>
<Filter-Name> reporter </filter-Name>
<URL-pattern>/* </url-pattern>
</Filter-mapping>

For example, in the Code 5-12 of the program list

Part of the web. xml file associated with the servlet. The name pagename is followed by a JSP page named testpage. jsp.

And URLs starting with http: // host/webappprefix/urltest2/are associated.

<Web-app>
<Filter>
<Filter-Name> reporter </filter-Name>
<Filter-class> moresevlets. reportfilter </filter-class>
</Filter>
<! --... -->
<Filter-mapping>
<Filter-Name> reporter </filter-Name>
<Servlet-Name> pagename </servlet-Name>
</Filter-mapping>
<! --... -->
<Servlet>
<Servlet-Name> pagename </servlet-Name>
<JSP-File>/realpage. jsp </JSP-File>
</Servlet>
<! --... -->
<Servlet-mapping>
<Servlet-Name> pagename </servlet-Name>
<URL-pattern>/urltest2/* </url-pattern>
</Servlet-mapping>
<! --... -->
</Web-app>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~

When you specify initialization parameters or custom URLs for a servlet or JSP page, you must first name the servlet or JSP page. The servlet element is used to complete this task.
The servlet-mapping 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 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 of a single session object,

You can also use the session-config element to specify the default timeout value.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The context-Param element declares the initialization parameters within the application range.

--------------------- The context-Param element must appear after any document-related elements (icon, display-name, or description) and before the filter, filter-apping, listener, or servlet elements. To ensure portability, elements in Web. xml must be declared in the correct order.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The listener servlet API Version 2.3 adds support for event listening programs,

You will be notified of modifying or deleting sessions or servlet environments. The listener element specifies the event listener class.

 

Mime-mapping the mime-mapping element provides this guarantee if the web application wants to assign specific MIME types to special files.

 

The Welcom-file-list welcome-file-list element indicates which file the server uses when it receives a URL that references a directory name rather than a file name.

 

 

**************************************** **************************************** ************

 

 

 

 

 

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.