Default settings for Servlets

Source: Internet
Author: User

If the mapping path for a servlet is a forward slash/, the servlet represents the default servlet for the current web App
When the servlet server receives an access request, the default servlet processing request is invoked if the URL of the matching <servlet-mapping> element is not found in the Web. xml file
That is, the default servlet is used to process access requests that are not processed by other Servlets
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>
  <!--mapping default servlet-- >
  <servlet-mapping>
    <servlet-name>TestServlet01</servlet-name>
    < Url-pattern>/</url-pattern>
  </servlet-mapping>

Launch Tomcat, enter the URL in the browser
Http://localhost:8080/chapter04/abcd
The results are shown below

As you can see, when the URL path is freely entered
can still access TestServlet01

Attention
The Web. xml file under the Tomcat installation directory
A default servlet is also configured
Configured as follows

<servlet>
        <servlet-name>default</servlet-name>
        <servlet-class> Org.apache.catalina.servlets.defaultservlet</servlet-class>
        <load-on-startup>1</ load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>default</ servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

Org.apache.catalina.servlets.DefaultServlet, which is set as the default servlet
All Web apps work on the Tomcat server, and when a web app doesn't have a default servlet, it calls the default servlet on Tomcat
When a client accesses a static HTML file in a Tomcat server, Defaultservlet will determine if the HTML file exists
If present, the data is sent back to the client in the form of a stream
Otherwise, a 404 error will be reported

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.