1

Is there any way to map all css resources so that they are all served from /css folder from SpringMVC? Ex. /login/sampleUser/ie.css maps to /css/ie.css

I have been trying using <mvc:resources mapping="/css/**" location="/css/" >, but seems not to work.

Thanks

1 Answer 1

2

You can be use the Tuckey Url Rewrite Filter. There you can define complexer rewrite rules.

 <!-- I do not know if this fiter works (correctly), but it should
      demonstrate how it works-->
 <rule>
    <!-- redirect everything that ends with .css
         to resources, with same file name -->
    <from>/(.*)/$.css</from>
    <to type="redirect">/resouces/$1</to>
 </rule>
Sign up to request clarification or add additional context in comments.

3 Comments

Interesting. Is there any way to rewrite using the servlet context? Ex. http://localhost:8080/myContext/anyUser/css/ie.css to http://localhost:8080/myContext/css/ie.css? All the examples seem to map to root directly. Ex. http://localhost:8080/myContext/anyUser/css/ie.css to http://localhost:8080/css/ie.css
The Tuckey Url Rewrite Filter works within you Application, so you can not rewrite to an other application.
Actually, you can and that's what happens when you "redirect" in your example. The correct rule should be something like this: <rule> <from>.+/css/(.*)$</from> <to type="forward" last="true">/css/$1</to> </rule>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.