Web. XML in Servlet

Source: Internet
Author: User

<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

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.