views:

1236

answers:

4

Hi, 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.)

+3  A: 

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.

GaryF
thanks, hmm.. I was very near to find this solution in ROO generated code.. ;)
Nachiket
Slightly off-topic but Roo is well worth looking into for building web-apps. Definitely one to keep an eye on.
GaryF
I have already started a demo project.. :) I love it.. because.. it does what i do manually..
Nachiket
+2  A: 

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

ptomli
thanks for the solution... Spring ROO gives Tuckey as default URL rewriting..
Nachiket
A: 

Actually I am trying to serve static resources in a Roo generated application as well, but cannot get it to work. I want to be able to run my selenium-tests directly from the webapps itself using selenium core. I have put it under /sr/main/webapp/selenium/core/

But when I try to access /sr/main/webapp/selenium/core/TestRunner.html it get the default error page from Roo.

Can you please help me with the rewrites/url-mapping?

er4z0r
O.K. Got it working now. Typo in the path *argh*
er4z0r
A: 

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.

pHk