In my Spring web-app i have mapped /app/*
to dispatcher servlet. What is the best approach in that scenerio to separate a static content like images
, .js
, .css
from dispatcher ?
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/app/*</url-pattern>
</servlet-mapping>
For example, when i open url: http://server/context/app/users
and on users.jsp have <img src="images/test.png"/>
i get no image because http://server/conext/app/users/images/test.png
is not a right url.
Now i use absolute path like: <img src="/context/images/test.png"/>
but it complicates JSP code a little and searching something better.
You can use <mvc:resources>
to tell the DispatcherServlet
that certain paths should be handles as static resources.
See section 15.12.4 of the Spring 3.0.x manual for how to configure it.
I serve static content using this configuration which will default if there is no handler mapping found for a URL and just serves the URL.
<mvc:default-servlet-handler/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With