Multiple mappings for Servlets

Source: Internet
Author: User
virtual path

In the Web. xml file, a <Servlet-mapping> element
Used to map the external access path of a servlet, which is called a virtual path
For example, Helloworldservlet, the mapped virtual path is
/helloworldservlet
Create a virtual path to the servlet so that the client can access the servlet's multiple mappings

Refers to the same servlet, which can be mapped to multiple virtual paths
Clients can implement access to the same servlet through multiple paths
Servlet Multi-mapping is implemented in two configurations with multiple <servlet-mapping> elements

Sample code

<servlet>
    <description></description>
    <display-name>testservlet01</ display-name>
    <servlet-name>TestServlet01</servlet-name>
    <servlet-class> cn.itcast.chapter04.servlet.testservlet01</servlet-class>
  </servlet>
  <!--map to Servlet01-- >
  <servlet-mapping>
    <servlet-name>TestServlet01</servlet-name>
    < url-pattern>/servlet01</url-pattern>
  </servlet-mapping>
  <!--map to Servlet02--
  <servlet-mapping>
    <servlet-name>TestServlet01</servlet-name>
    <url-pattern >/Servlet02</url-pattern>

  </servlet-mapping>

Visit Servlet01

Visit Servlet02

Access to all two addresses TestServlet01
By configuring multiple <servlet-mapping> elements, you can configure multiple <url-pattern> child elements for a servlet's Multimap

In a <servlet-mapping> element, configure multiple <url-pattern> child elements
Sample code

<servlet>
    <description></description>
    <display-name>testservlet01</ display-name>
    <servlet-name>TestServlet01</servlet-name>
    <servlet-class> cn.itcast.chapter04.servlet.testservlet01</servlet-class>
  </servlet>
  <!-- Maps to Servlet01 and Servlet02-
  <servlet-mapping>
    <servlet-name>testservlet01</ servlet-name>
    <url-pattern>/Servlet01</url-pattern>
    <url-pattern>/servlet02</ Url-pattern>
  </servlet-mapping>

Visit Servlet01

Visit Servlet02

Two servlet paths can be accessed TestServlet01
By configuring multiple <url-pattern> child elements in a <servlet-mapping> element
You can also implement multiple mappings for a 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.