<servlet>
<servlet-mapping>
The relationship between them can be one-to-one, but one-to-many relationships.
<servlet>
<servlet-name>myfirst_servlet</servlet-name>//This is a sign that corresponds to the <servlet-mapping> formation
The <servlet-class>helloworldservle</servlet-class>//server accesses this. class file and should be written as package name/class name if it is packaged
</servlet>
<servlet-mapping>
<servlet-name>myfirst_servlet</servlet-name>//This corresponds to the servlet
<url-pattern>hello</url-pattern>//the path name of the user's data in the client browser
</servlet-mapping>
The overall process is this:
A Helloworldservle.java file was written. When it is finished, it is automatically compiled in MyEclipse. The compiled file is a helloworldservle.class file. Create a new folder in the Tomcat folder my, and in which you continue to create a name for the Web-inf folder that contains the Web. xml file. The contents of the file are as follows. A classes folder and a Lib folder. Copy the Helloworldservle.class file to the Classes folder.
<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE Web-app
Public "-//sun Microsystems, INC.//DTD Web application 2.2//en"
"Http://java.sun.com/j2ee/dtds/web-app_2_2.dtd" >
<web-app>
<servlet>
<servlet-name>myfirst_servlet</servlet-name>
<servlet-class>HelloWorldServle</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>myfirst_servlet</servlet-name>
<url-pattern>hello</url-pattern>
</servlet-mapping>
</web-app>
Start the Tomcat server and enter: Http://127.0.0.1:8080/my/hello in the browser. The server automatically looks for and resolves: Tomcat in webapps--"my--" Web-inf under the Web. xml file. First, I found the hello in <servlet-mapping> <url-pattern>, so the server knows its <servlet-name> is: Myfirst_servlet, Immediately the server goes to the <servlet> tab to look for <servlet-name> name Myfirst_servlet. When found, follow the path specified in <servlet-class> to parse the Helloworldservle file back to the client browser.
This process is the whole process of servlet running.
Web. XML in Servlet