I am trying to display an image stored at local file system outside my webapp. following question: Simplest way to serve static data from outside the application server in a Java web application
EDIT: I want file to be outside the webapp cause these images are uploaded by user, If I put them inside webapp, I might loose them when I redeploy the web app
but the file is not being displayed on the webpage. When I try opening the file through: localhost:8080/images/imageName.jpg it gives me a resource not available error.
I have added the context in my server.xml (traversing throug Servers->Config->server.xml) :
........
<Context docBase="DMSystemV1.0" path="/DMSystemV1.0" reloadable="true" source="org.eclipse.jst.jee.server:DMSystemV1.0"/>
<Context docBase="/Projects/SpringExample/Images" path="/images"/>
</Host>
Also my web.xml looks like this:
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/static/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>DMSystem</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>DMSystem</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
The place where I want it to get displayed: <img src="/images/${imagePath}" alt="Item's image">
Mytomcat is in: F:\Software\Servers\tomcat7\tomcat7 While the image folder is: F:\Projects\SpringExample\Images
Is the image path is taken relative to the tomcat folder?
Also,write now I am hard-coding the upload path (in my upload servlet) and download path in server.xml, is there a way to provide them as confign or set up info?