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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:24:09+00:00 2026-05-21T07:24:09+00:00

My goal is to map /{any path} and *.html to a servlet without mapping

  • 0

My goal is to map /{any path} and *.html to a servlet without mapping /*. For example:

map:
/foo
/foobar/
/bar.html
/foo/bar.html

don't map:
/foo.js
/bar.pdf

In order to do this, I have a servlet and welcome file mapped like so:

web.xml:

<servlet-mapping>
 <servlet-name>someServlet</servlet-name>
 <url-pattern>*.html</url-pattern>
</servlet-mapping>

<welcome-file-list>
 <welcome-file>index.html</welcome-file>
</welcome-file-list>

and in a controller, I have

@RequestMapping(value="/index.html", method=RequestMethod.GET)
public ModelAndView showPage(HttpServletRequest request){
  ...
}

this will not work – the servlet will not be triggered on /test. However, I’ve found that if I create a blank file at /test/index.html, then it does work – I assume the default servlet is somehow helping by finding the index.html.

Unfortunately, I can’t rely on static files. Is there any way I can make this mapping work without the blank file hack and without mapping /* to the servlet?

  • 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-21T07:24:10+00:00Added an answer on May 21, 2026 at 7:24 am

    The answer depends on whether you want Spring to handle:

    • Only URLs ending in .html or without an extension, or
    • All URLs, except those ending in .js and .pdf, etc

    Both those rules would match the list you gave in your question. However the second one is easier to implement. If you have a known list of extensions that you don’t want Spring to handle, simply map those files in your web.xml file to the default handler like this:

    <servlet-mapping>
        <servlet-name>someServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>*.js</url-pattern>
    </servlet-mapping>
    

    However this only works if you know all the extensions you don’t want Spring to handle, because you have to list each extension in web.xml.

    If you really want to reject any extension other than .html then you need to override Spring’s default behaviour somehow. I won’t go in to that here because I think the above is a better option. But two possible ways of doing that are explained in this question: spring mvc how to bypass DispatcherServlet for *.html files?

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

Sidebar

Related Questions

I have a simple goal: Map Ctrl-C, a command I don't think I've ever
I'm new to Google map api. My goal is to overlay a series of
If I have to following HTML which is a image of a map. The
My goal is to store all the keys of a map (first item) to
I've started developing a small app which main goal is to draw a map
Is there any reason not to map Controllers as interfaces? In all the examples
Goal: Get the TEXT address and then display the street view and map view
I have a large PDF file that is a floor map for a building.
The final goal is to display a few kml overlays on one map and
You have a map of square tiles where you can move in any of

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.