Detailed explanation of web.xml file
Preface: web.xml is used in general web projects. .xml is mainly used for configuration and can facilitate the development of web projects. web.xml is mainly used to configure Filter, Listener, Servlet, etc. But it should be noted that web.xml is not necessary. A web project does not need a web.xml file.
1. WEB project loading web.xml process
After personal testing, WEB The project loading order has nothing to do with the configuration order of element nodes in the file. That is, filter will not be loaded first because filter is written before listener. The loading sequence of the WEB container is: ServletContext -> context-param -> listener -> filter -> servlet. And these elements can be configured anywhere in the file.
The loading process sequence is as follows:
When starting a WEB project, the WEB container will read its The configuration file web.xml reads the two nodes
and . #Emergency, create a ServletContext (servlet context), all parts of this web project will share this context.
The container converts
into a key-value pair and hands it to servletContext. The container creates a class instance in
and creates a listener.
##2. Detailed explanation of web.xml file elements
1. schema
The schema file of web.xml is defined by Sun. The root element of each web.xml file is <?xml version="1.0" encoding="UTF-8"?><web-app></web-app>
2.
<icon>
<small-icon>/images/app_small.gif</small-icon>
<large-icon>/images/app_large.gif</large-icon></icon>
3.
<display-name>Tomcat Example</display-name>4. Descriptive text related to this
<disciption>Tomcat Example servlets and JSP pages.</disciption>
5,
Declaration application Initialization parameters within the range. It is used to provide key-value pairs, that is, application context information, to the ServletContext. Our listeners, filters, etc. will use the information in these contexts during initialization. In the servlet, it can be obtained through getServletContext().getInitParameter("context/param").
<context-param>
<param-name>ContextParameter
<param-value>test</param-value>
<description>It is a test parameter.</description></param-name></context-param>
6.
## Combine a name with an implementation of javaxs.servlet.Filter The interface is associated with the class.
<filter> <filter-name>setCharacterEncoding</filter-name> <filter-class>com.myTest.setCharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param></filter><filter-mapping> <filter-name>setCharacterEncoding</filter-name> <url-pattern>/*</url-pattern></filter-mapping>7.
<listener> <listerner-class>com.listener.SessionListener </listerner-class></listener>8.
##
#
##
Specifies the complete content of a JSP web page in the web site Path is used to define parameters. There can be multiple init-params. Access initialization parameters through the getInitParamenter(String name) method in the servlet class 指定当Web应用启动时,装载Servlet的次序。当值为正数或零时:Servlet容器先加载数值小的servlet,再依次加载其他数值大的servlet。当值为负或未定义:Servlet容器将在Web客户首次访问这个servlet时加载它。 用来定义servlet所对应的URL,包含两个子元素 指定servlet的名称 指定servlet所对应的URL
<!-- 基本配置 --><servlet> <servlet-name>snoop</servlet-name> <servlet-class>SnoopServlet</servlet-class></servlet><servlet-mapping> <servlet-name>snoop</servlet-name> <url-pattern>/snoop</url-pattern></servlet-mapping><!-- 高级配置 --><servlet> <servlet-name>snoop</servlet-name> <servlet-class>SnoopServlet</servlet-class> <init-param> <param-name>foo</param-name> <param-value>bar</param-value> </init-param> <run-as> <description>Security role for anonymous access</description> <role-name>tomcat</role-name> </run-as></servlet><servlet-mapping> <servlet-name>snoop</servlet-name> <url-pattern>/snoop</url-pattern></servlet-mapping>
9、
单位为分钟。
<session-config> <session-timeout>120</session-timeout></session-config>
10、
<mime-mapping> <extension>htm</extension> <mime-type>text/html</mime-type></mime-mapping>
11、
<welcome-file-list> <welcome-file>index.jsp</welcome-file> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file></welcome-file-list>
12、
<!-- 1、通过错误码来配置error-page。当系统发生×××错误时,跳转到错误处理页面。 --><error-page> <error-code>404</error-code> <location>/NotFound.jsp</location></error-page><!-- 2、通过异常的类型配置error-page。当系统发生java.lang.NullException(即空指针异常)时,跳转到错误处理页面。 --><error-page> <exception-type>java.lang.NullException</exception-type> <location>/error.jsp</location></error-page>
13、
:设定的说明 :设定名称 :设定值所影响的范围,如: /CH2 或 /*.jsp :若为 true,表示不支持 EL 语法 :若为 true,表示不支持 语法 :设定 JSP 网页的编码 :设置 JSP 网页的抬头,扩展名为 .jspf :设置 JSP 网页的结尾,扩展名为 .jspf
<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> <url-pattern>/jsp/* </url-pattern> <el-ignored>true</el-ignored> <page-encoding>GB2312</page-encoding> <scripting-invalid>true</scripting-invalid> <include-prelude>/include/prelude.jspf</include-prelude> <include-coda>/include/coda.jspf</include-coda> </jsp-property-group></jsp-config>
对于Web 应用程式来说,Scriptlet 是个不乐意被见到的东西,因为它会使得HTML 与Java 程式码交相混杂,对于程式的维护来说相当的麻烦,必要的时候,可以在web.xml 中加上
3、Mapping规则
当一个请求发送到servlet容器的时候,容器先会将请求的url减去当前应用上下文的路径作为servlet的映射url,比如我访问的是http://localhost/test/aaa.html,我的应用上下文是test,容器会将http://localhost/test去掉,剩下的/aaa.html部分拿来做servlet的映射匹配。这个映射匹配过程是有顺序的,而且当有一个servlet匹配成功以后,就不会去理会剩下的servlet了。
其匹配规则和顺序如下:
精确路径匹配。例子:比如servletA 的url-pattern为 /test,servletB的url-pattern为 /* ,这个时候,如果我访问的url为http://localhost/test ,这个时候容器就会先 进行精确路径匹配,发现/test正好被servletA精确匹配,那么就去调用servletA,也不会去理会其他的servlet了。
Longest path matching. Example: The url-pattern of servletA is /test/*, and the url-pattern of servletB is /test/a/*. When accessing http://localhost/test/a, the container will select the servlet with the longest path. Match, which is servletB here.
#Extension matching, if the last segment of the URL contains an extension, the container will select the appropriate servlet based on the extension. Example: servletA's url-pattern: *.action
Starting with "/" and ending with "/*" are used for path mapping. Things starting with the prefix "*." are used for extended mapping. So, why is it wrong to define a seemingly normal match like "/*.action"? Because this match belongs to both path mapping and extended mapping. The container cannot determine
.The above is the detailed content of Detailed analysis of web.xml file content. For more information, please follow other related articles on the PHP Chinese website!

The implementation of RSS in XML is to organize content through a structured XML format. 1) RSS uses XML as the data exchange format, including elements such as channel information and project list. 2) When generating RSS files, content must be organized according to specifications and published to the server for subscription. 3) RSS files can be subscribed through a reader or plug-in to automatically update the content.

Advanced features of RSS include content namespaces, extension modules, and conditional subscriptions. 1) Content namespace extends RSS functionality, 2) Extended modules such as DublinCore or iTunes to add metadata, 3) Conditional subscription filters entries based on specific conditions. These functions are implemented by adding XML elements and attributes to improve information acquisition efficiency.

RSSfeedsuseXMLtostructurecontentupdates.1)XMLprovidesahierarchicalstructurefordata.2)Theelementdefinesthefeed'sidentityandcontainselements.3)elementsrepresentindividualcontentpieces.4)RSSisextensible,allowingcustomelements.5)Bestpracticesincludeusing

RSS and XML are tools for web content management. RSS is used to publish and subscribe to content, and XML is used to store and transfer data. They work with content publishing, subscriptions, and update push. Examples of usage include RSS publishing blog posts and XML storing book information.

RSS documents are XML-based structured files used to publish and subscribe to frequently updated content. Its main functions include: 1) automated content updates, 2) content aggregation, and 3) improving browsing efficiency. Through RSSfeed, users can subscribe and get the latest information from different sources in a timely manner.

The XML structure of RSS includes: 1. XML declaration and RSS version, 2. Channel (Channel), 3. Item. These parts form the basis of RSS files, allowing users to obtain and process content information by parsing XML data.

RSSfeedsuseXMLtosyndicatecontent;parsingtheminvolvesloadingXML,navigatingitsstructure,andextractingdata.Applicationsincludebuildingnewsaggregatorsandtrackingpodcastepisodes.

RSS documents work by publishing content updates through XML files, and users subscribe and receive notifications through RSS readers. 1. Content publisher creates and updates RSS documents. 2. The RSS reader regularly accesses and parses XML files. 3. Users browse and read updated content. Example of usage: Subscribe to TechCrunch's RSS feed, just copy the link to the RSS reader.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software