In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the example analysis of the content of web.xml file, which is very detailed and has certain reference value. Friends who are interested must finish reading it!
Detailed explanation of web.xml file
General web projects will be used in web.xml,web.xml mainly for configuration, it is convenient to develop web projects. Web.xml is mainly used to configure Filter, Listener, Servlet, etc. But to make it clear that web.xml is not necessary, a web project can be without an web.xml file.
1. WEB project loading web.xml process
After personal testing, the loading order of the WEB project is independent of the configuration order of the element nodes in the file. That is, filter will not be loaded first because filter is written in front of listener. The loading order of the WEB container is: ServletContext-> context-param-> listener-> filter-> servlet. And these elements can be configured anywhere in the file.
The order of the loading process is as follows:
When you start a WEB project, the WEB container reads its configuration file web.xml, reads, and two nodes.
Urgently, create a ServletContext (servlet context) that will be shared by all parts of the web project.
The container is converted to a key-value pair and handed over to servletContext.
Create a listener by creating a class instance in the container creation.
2. Detailed explanation of web.xml file elements
1 、 schema
The schema file for web.xml is defined by Sun, and the root element of each web.xml file must indicate which schema file the web.xml uses. All the other elements are put in it.
2. Web application icon
Point out the large icons and small icons used by IDE and GUI tools to represent Web applications.
/ images/app_small.gif / images/app_large.gif
3. Name of Web application
Providing a GUI tool may be used to mark a name for this particular Web application
Tomcat Example
4. Web application description
Give illustrative text out of this relevance
Tomcat Example servlets and JSP pages.
5. Context parameters
Declare initialization parameters within the scope of application. It is used to provide ServletContext with key-value pairs, that is, application context information. Our listener, filter, etc., use these contextual information during initialization. You can get it in servlet through getServletContext (). GetInitParameter ("context/param").
ContextParameter test It is a test parameter.
6. Filter
Associate a name with a class that implements the javaxs.servlet.Filter interface.
SetCharacterEncoding com.myTest.setCharacterEncodingFilter encoding UTF-8 setCharacterEncoding / *
7. Listener
Com.listener.SessionListener
8 、
The data used to declare an servlet consists of the following child elements:
Specify the name of the servlet
Specify the class name of the servlet
Specify the full path to a JSP page in the web site
Used to define parameters, but there can be multiple init-param. Access initialization parameters through the getInitParamenter (String name) method in the servlet class
Specifies the order in which the Servlet is loaded when the Web application starts. When the value is a positive number or 00:00: the Servlet container loads servlet with small values first, and then loads other servlet with large values in turn. When the value is negative or undefined: the Servlet container will load the servlet the first time the Web customer accesses it.
Used to define the URL corresponding to servlet, which contains two child elements
Specify the name of the servlet
Specify the URL for servlet
Snoop SnoopServlet snoop / snoop snoop SnoopServlet foo bar Security role for anonymous access tomcat snoop / snoop
9. Session timeout configuration
In minutes.
one hundred and twenty
10 、
Htm text/html
11. Welcome document page
Index.jsp index.html index.htm
12. Error page
404 / NotFound.jsp java.lang.NullException / error.jsp
13. Set jsp
Including and two child elements. The element already exists in JSP 1.2; it's a new element in JSP 2.0.
The element mainly has eight child elements, which are:
Description of the settin
: set name
Set the range of values affected, such as / CH2 or / * .jsp
: true indicates that EL syntax is not supported
: true indicates that syntax is not supported
: set the encoding of JSP web pages
Set the header of the JSP page with a .jspf extension
: sets the end of the JSP page with a .jspf extension
Taglib / WEB-INF/tlds/MyTaglib.tld Special property group for JSP Configuration JSP example. JSPConfiguration / jsp/* true GB2312 true / include/prelude.jspf / include/coda.jspf
For Web applications, Scriptlet is an unpleasant thing to see because it confuses HTML with Java code, which is troublesome for program maintenance. If necessary, you can add tags in web.xml to set that all JSP pages are not allowed to use Scriptlet.
3. Mapping rules
When a request is sent to the servlet container, the container will first take the requested url minus the path of the current application context as the mapping url of the servlet. For example, I am accessing http://localhost/test/aaa.html, my application context is test, the container will remove the http://localhost/test, and the rest of the / aaa.html part will be used for servlet mapping matching. The mapping matching process is sequential, and when one servlet matches successfully, the rest of the servlet is ignored.
The matching rules and order are as follows:
Exact path match. Example: for example, the url-pattern of servletA is / test,servletB and the url-pattern is / *. At this time, if the url I visit is http://localhost/test, the container will first perform exact path matching and find that / test is exactly matched by servletA, then call servletA and ignore other servlet.
The longest path matches. 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 to match, that is, the 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: url-pattern:*.action of servletA
Those that start with "/ 'and end with" / * "are used for path mapping. what starts with the prefix" *. "is used for extension mapping. so why is it wrong to define a normal-looking match like" / * .action "? because this match belongs to both a path mapping and an extension mapping, the container cannot judge.
The above is all the contents of the article "sample Analysis of the contents of web.xml Files". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.