i’m trying to find a way remap a path to an absolute one in order to retrieve images stored in the server filesystem, i’m also using spring mvc but the <mvc:resource> can’t map absolute paths, and i can’t find a nice way to do this with spring controllers
i.e. I need to map all the image requests from /images/** to /root/var/img/**, in this way when a client browser try to load an image of the page, every images stays in the path above mentioned
You can create a new context with
docBasereferencing to your folder (/root/var/img) It should look like this:Refer to Tomcat context configuration documentation for more details (e.g., for Tomcat 6: Apache Tomcat Configuration Reference: The Context Container).
Introduction to this document lists possible places where context elements can be defined.
EDIT
As I mentioned in comments, Spring-specific way to do this without creating any new context seems to be using RedirectView (link to Spring v2.5 JavaDoc). According to JavaDoc:
EDIT2
It seems I’ve misunderstood RedirectView purpose, which is a good old URL redirection. Thus, answer by @Jens should be more appropriate (+1). I still wonder if there’s an existing standard solution in Spring (what I originally thought RedirectView would do..) It’s not like there’s much code to write, but still 🙂
EDIT3
After reading more on this topic, I found out that
<mvc:resources>is able to do this (i.e., mapping resource using not only relative path, or classpath), you just need to correctly configure location using file: prefix . In fact, there’s already answer on SO that explains exactly what you need to do: Spring : serving static resources outside context root