Javaweb project, Web. XML for the basic configuration of the servlet:
We note that there is also a Web. xml file in Conf under Tomcat, and yes, all of the Javaweb projects are inherited from Web. XML from the server.
Take a look at this web. xml:
[HTML]View PlainCopy
- <? XML version= "1.0" encoding="iso-8859-1"?>
- <Web-app xmlns="Http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee
- Http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd "
- version="3.0">
- <servlet>
- <servlet-name>default</servlet-name>
- <servlet-class>org.apache.catalina.servlets.defaultservlet</servlet-class >
- <init-param>
- <param-name>debug</param-name>
- <param-value>0</param-value>
- </init-param>
- <init-param>
- <param-name>listings</param-name>
- <param-value>false</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet>
- <servlet-name>jsp</servlet-name>
- <servlet-class>org.apache.jasper.servlet.jspservlet</servlet-class>
- <init-param>
- <param-name>fork</param-name>
- <param-value>false</param-value>
- </init-param>
- <init-param>
- <param-name>xpoweredby</param-name>
- <param-value>false</param-value>
- </init-param>
- <load-on-startup>3</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>default</servlet-name>
- <url-pattern>/</url-pattern>
- </servlet-mapping>
- <servlet-mapping>
- <servlet-name>jsp</servlet-name>
- <url-pattern>*.jsp</url-pattern>
- <url-pattern>*.jspx</url-pattern>
- </servlet-mapping>
- <session-config>
- <session-timeout>30</session-timeout>
- </session-config>
- <!--This omits the definition of a MIME type of about 4,000 lines, giving only two definitions of MIME types- -
- <mime-mapping>
- <extension>bmp</extension>
- <mime-type>image/bmp</mime-type>
- </mime-mapping>
- <mime-mapping>
- <extension>htm</extension>
- <mime-type>text/html</mime-type>
- </mime-mapping>
- <welcome-file-list>
- <welcome-file>index.html</welcome-file>
- <welcome-file>index.htm</welcome-file>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
- </Web-app>
And after we have created a servlet, we need to configure the following basic content:
[HTML]View PlainCopy
- <servlet>
- <servlet-name>servlet name (self-starting, do not repeat)</servlet-name>
- <servlet-class>servlet class Path (xx.xx.xx.xxservlet)</servlet-class>
- </servlet>
- <servlet-mapping>
- <servlet-name>servlet name (same as above)</servlet-name>
- <url-pattern>/url name (own, do not repeat, note/, can not be lost)</url-pattern>
- </servlet-mapping>
The result is that a servlet class and URL path are bound together, meaning that our access to the/url name is actually accessing a servlet class;
In fact, the configuration of some development tools will be automatically configured, but we still need to understand, sometimes we need to match, or when you want to change.
Copyright notice: Here is Wolfarya's blog, are their own learning process, only for learning and reference, welcome to put forward comments and reprint qaq~
TOMCAT Web. XML Finishing Instructions