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?