Question

My Spring Dispatcher servlet url-pattern is /* (as spring MVC REST suggests)
Now all the request are resolved by this Servlet. even CSS/JS/Images also get resolved and handled by servlet..

So, Spring MVC tries to find controller.. :(

How to bypass this? Is there any standard way out of this problem??

& Don't want to change url-pattern to /rest/* (so, other static resources get accessed by /css/ or /js etc.)

Was it helpful?

Solution

You can map your controllers to a smaller set of URLS (i.e. /app/*), and then rewrite the URLs that your users actually see so that they don't even know about. Have a look at the mvc-basic webapp sample, particularly web.xml and urlrewrite.xml to see how this is done.

OTHER TIPS

Map the Spring dispatcher to some subsection of the URL space, and use Tuckey to rewrite URLs the user deals with.

http://www.example.org/app/controller/action -> http://www.example.org/controller/action

Just a heads-up update on this: the default rewrite configuration as defined in the Spring sample did not work out of the box for me. The rewrite rules for stylesheets, scripts, etc. were still processed to the /app/* rule, and subsequently handled by the DispatchServlet, which is not desirable.

I had to add the last="true" attribute to the styles/scripts/images rules to indicate that other rules should not apply, and I had to use the FreeMarker Spring URL macro in any CSS/JS include paths.

Just in case someone encounters the same problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top