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 261427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:25:52+00:00 2026-05-11T22:25:52+00:00

I want a Servlet to handle requests to files depending on prefix and extension,

  • 0

I want a Servlet to handle requests to files depending on prefix and extension, e.g.

prefix_*.xml

Since mapping on beginning AND end of request path is not possible, I have mapped all *.xml requests to my Servlet.
The question now is: how can I drop out of my servlet for XML files not starting with “prefix_”, so that the request is handled like a “normal” request to an xml file?

This is probably quite simple but I do not seem to be able to find this out… :-/

Thanks a lot in advance

  • 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-11T22:25:52+00:00Added an answer on May 11, 2026 at 10:25 pm

    I would strongly suggest using a proper MVC framework for this. As you’ve discovered, the flexibility of the standard servlet API is very limited when it comes to request dispatching.

    Ideally, you would be able to use your existing servlet code in combination with an MVC framework, with the framework doing the diapcthing based on path pattern, and your servlets doing the business logic. Luckily, Spring MVC allows you to do just that, using the ServletForwardingController. It’d be a very lightweight spring config.

    So you’d have something like this in your web.xml:

    <servlet>
       <servlet-name>myServlet</servlet-name>
       <servlet-class>foo.MyServlet</servlet-class>
    </servlet>
    
    <servlet>
       <servlet-name>spring</servlet-name>
       <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    </servlet>
    
    <url-mapping>
       <servlet-name>spring</servlet-name>
       <url-pattern>*</url-pattern>
    </url-mapping>
    

    You would then have a WEB-INF/spring-servlet.xml file like this:

    <beans>
        <bean name="/prefix*.xml" class="org.springframework.web.servlet.mvc.ServletForwardingController">
           <property name="servletName" value="myServlet"/>
        </bean>
    </beans>
    

    And that would be pretty much it. All requests for /prefix*.xml would go to myServlet, and all others would fall through to the container.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a servlet that handle certain HTTP requests and responses. I want to
I want to send a request to another server from my servlet and get
I want to redirect to home page if session get invalid. My spring-servlet.xml is
In my web.xml I have the following mapping <servlet-mapping> <servlet-name>mySite</servlet-name> <url-pattern>*.html</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>mySite</servlet-name>
I want to create a servlet that will allow me to upload image files
I have a Servlet class I made to handle functions I don't want to
In a Java Servlet I want to check programmatically whether a user is logged
I created one GWT webapplication project.Inthat i want to create servlet program,but in that
I want to call a Servlet from img src. I have defined a Servlet
i want to send arabic data from servlet using HTTPServletResponse to client i am

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.