Web. XML element Introduction

Source: Internet
Author: User

Web. XML element Introduction edit The web-inf of each station has a config file for Web. XML, which provides the configuration settings for our platform.The web. XML element DefinitionThe name and description of the platform do initialize the name of the servlet and the setting of the mapping session for the Environment parameter (context) set Mime for the Tag Library's mirroring JSP page Type handling error handling using JDNI to get platform resources to understand the set value of Web. XML, you must understand its schema, and know from Web. XML that its schema is customized by the Sum Microsystems company, if you want to know more about it, can go to this page, there is a more detailed introduction. Here I introduce the most commonly seen by us. 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.The Web. XML element specifically describes< description>; platform Description </discription>Make a description of the platform.< display-name>; platform name </display-name>Defines the name of the platform.< icon>The 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 platform, 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. Example:< display-name>develop example</display-name> < description>jsp 2.0 Tech book ' s examples</description> < icon> < SMA ll-icon>/images/small.gif</small-icon> < large-icon>/images/large.gir</large-icon> </icon >< distributable>The distributable element is an empty label, and its presence or absence can specify whether the platform can be distributed. If this element appears in Web. XML, the platform is designed to be decentralized across multiple JSP Container at development time.< 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>Example of setting a value for the context name:< context-param> < param-name>param_name</param-name> < PARAM-VALUE&GT;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 be obtained using the following methods: String Param_name=getservletcontext (). Getinitparamter ("Param_name");< 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.< Filter-name>filter's name </filter-name>Defines the name of the filter.< Filter-class>filter class name </filter-class>Defines the class name of the filter. Example: com.foo.hello example:< filter> < filter-name>setcharacterencoding</filter-name> < Filter-class>coreservlet. setcharacterencodingfilter</filter-class> < init-param> < param-name>encoding</param-name> < param-value>gb2312</param-value> </init-param> </filter>< 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.< Filter-name>filter's name </filter-name>Defines the name of the filter.< url-pattern>url</url-pattern>The URL that corresponds to Filter. For example:< url-pattern>/filter/hello</url-pattern>< Servlet-name>servlet's name < servlet-name>Defines the name of the servlet.< dispatcher>request| include| forward| error</disaptcher>Set the filter corresponding to the request method, there are rquest,include,forwar,error four kinds, the default is request. Example:< filter-mapping> < filter-name> gzipencoding</filter-name> < url-pattern>/*</url-pattern> </filter-mapping>< listener>The listener element is used to define the listener interface, and its primary child element is < listener-class>< Listen-class>listener class name </listener-class>Defines the class name for the listener. Example: com.foo.hello example:< listener> < Listener-class>coreservlet. contenxtlistener</listener-class> </listener>< servlet-mapping>The servlet-mapping element contains two child elements servlet-name and url-pattern. Used to define the URL of the servlet.< Servlet-name>servlet's name </servlet-name>Defines the name of the servlet.< Url-pattern>servlet url</url-pattern>Defines the rul that the Servlet corresponds to. Example:< url-pattern>/servlet/hello</url-pattern> example:< servlet-mapping> < servlet-name>loginchecker</servlet-name> < url-pattern>/loginchecker</url-pattern> </ Servlet-mapping>< session-config>The session-config contains a child element, Session-timeout. Defines the session parameter in the Web platform.< session-timeout>; min </session-timeout>Defines the expiration date for all sessions of this web site. Units are minutes. Example:< session-config> < session-timeout>20</session-timeout> </ Session-config>< mima-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. welcome-file-list contains a child element welcome-file. Used to define the first page list.< welcome-file>; To specify the home 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 first page. Example:< welcome-file-list> < welcome-file>index.jsp</welcome-file> < welcome-file>index.htm</welcome-file> </ Welcome-file-list>< error-page>The Error-page element contains three child elements, Error-code,exception-type, and location. The type of error code or exception (exception) corresponds 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>Examples of related resource paths within a web platform:< 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>< 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.< 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.< page-encoding>encoding</page-encoding>Set the encoding of the JSP Web page< include-prelude>.jspf</include-prelude>Sets the header of the JSP Web page with the extension. JSPF< include-coda>.jspf</include-coda>Set the end of the JSP Web page with a. JSPF sample extension:< 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>The Resource-ref element consists of five child elements description,res-ref-name,res-type,res-auth,res-sharing-scope. Use Jndi to get platform available resources.< description>; description </description>Resource Description< rec-ref-name>; resource Name </rec-ref-name>Resource Name< res-type>; resource types </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> The common set values in the Web. XML element are described above. This article from L101Y1982J's blog: "Web. Xml detailed"

Web. XML element Introduction

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.