Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6822819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:42:32+00:00 2026-05-26T21:42:32+00:00

I have a confusion regarding the structure of the web.xml for the servlet mapping,

  • 0

I have a confusion regarding the structure of the web.xml for the servlet mapping, I don’t have any problem by executing it but I am trying to figure it how why we have such a pattern in the deployment descriptor.

<web-app>
    <servlet>
         <servlet-name>Servlet1</servlet-name>
         <servlet-path>foo.Servlet</servlet-path>
    </servlet>
    <servlet-mapping>
         <servlet-name>Servlet1</servlet-name>
         <url-pattern>/enroll</url-pattern>
    </servlet-mapping>
</web-app>

Now as far as my understanding whenever a request is comes for url-pattern “/enroll”, servlet container is going to match the servlet-name with the url-pattern and will try to find the corresponding servlet-path and will forward the control to foo.Servlet. so basically there would be two passes one for finding servlet-name and another for servlet-path, my question is if container is designed to work in the following way

<web-app>
        <servlet>
             <servlet-name>foo.Servlet</servlet-path>
             <url-pattern>/enroll</url-pattern>
        </servlet>
</web-app>

what would be the drawback if we use the following approach. Wouldn’t that be more efficient and the response time would be fast.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:42:33+00:00Added an answer on May 26, 2026 at 9:42 pm

    It allows servlets to have multiple servlet mappings:

    <servlet>
        <servlet-name>Servlet1</servlet-name>
        <servlet-path>foo.Servlet</servlet-path>
    </servlet>
    <servlet-mapping>
        <servlet-name>Servlet1</servlet-name>
        <url-pattern>/enroll</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Servlet1</servlet-name>
        <url-pattern>/pay</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Servlet1</servlet-name>
        <url-pattern>/bill</url-pattern>
    </servlet-mapping>
    

    It allows filters to be mapped on the particular servlet:

    <filter-mapping>
        <filter-name>Filter1</filter-name>
        <servlet-name>Servlet1</servlet-name>
    </filter-mapping>
    

    Your proposal would support neither of them. Note that the web.xml is read and parsed only once during application’s startup, not on every HTTP request as you seem to think.

    Since Servlet 3.0, there’s the @WebServlet annotation which minimizes this boilerplate:

    @WebServlet("/enroll")
    public class Servlet1 extends HttpServlet {
    

    See also:

    • How do servlets work? Instantiation, sessions, shared variables and multithreading
    • Difference between each instance of servlet and each thread of servlet in servlets?
    • Our Servlets wiki page
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Regarding the below code snippet i understand the bit but i have few confusion
I have confusion regarding COBOL data types. Like in many interviews it is asked
I have some confusion regarding Events . What are the basic differences between C#
I have little bit confusion regarding apache tomcat installation. So, I would like to
I have confusion regarding that coregraphics layers are same as core animation layers?
Possible Duplicate: Benefits of inline functions in C++? I have a confusion regarding the
I have a little confusion regarding difference between ORM and PDO? Is PDO a
I have a slight confusion regarding HTTPOnly attribute in cookies. I am aware that
I have a bit of confusion regarding static Combine( ) provided in System.Delegate( )
I have some confusion regarding where you put regular java code in an android

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.