0

I have a spring project where, on a linux/tomcat6 server we have an external folder for person photos inside "/var/projectname/personphotos". Tried making a symbolic link and the like and nothing seems to work, the application cannot see the external folder. I happened to stunble upon the <mvc:resources> tag and the <mvc:annotation-driven /> .How do I add it to the project ? I was thinking something like

<mvc:resources mapping="/personphotos/" location="/var/projectname/personphotos" />

and in the application i can have something like <img src="/personphotos/bla-bla.jpg"/>

All of the tutorials say to use the tags but they don't say where to place it. I assume the location must be understood, forgive my ignorance. I tried adding it to the applicationcontext.xml and that blew-up with errors. Other tutorials were saying to edit the servlet-context.xml, wherever that is ? see here

I am using spring 3.0.7 with STS and I tried changing to 3.1.0 in the pom file. The version change caused mvn tomcat:run to give some errors. I saw somewhere that the mvc:resource tage was available in 3.0.4 or highter, i guess I am safe for now. Please help to clear up these ambiguities.

Community
  • 1
  • 1
Faiyet
  • 5,341
  • 14
  • 51
  • 66

1 Answers1

2

It has to be in your servlet-context.xml file, probably this way:

<mvc:resources mapping="/personphotos/**" location="/var/projectname/personphotos" />

and you can access it using:

<img src="${pageContext.request.contextPath}/personphotos/bla-bla.jpg"/>

the starting part is to make sure that you application context part gets added in too.

EDIT For the benefit of others, the Final thing which is working is

<mvc:resources mapping="/personphotos/**" location="file:/var/projectname/personphotos" />
Faiyet
  • 5,341
  • 14
  • 51
  • 66
Biju Kunjummen
  • 49,138
  • 14
  • 112
  • 125
  • I cannot find a file called servlet-context.xml in my project. I can find context.xml inside"src/main/webapp/META-INF" apart form that there is the applicationcontext.xml inside "src/main/resources/META-INF/spring/applicationcontext.xml". I am not sure where to find servlet-context.xml – Faiyet Sep 26 '12 at 16:36
  • yes, I meant the context file that you have registered against the DispatcherServlet, look in your web.xml , you should see an entry for DispatcherServlet, the init-param value should indicate which application context file it uses - it should be the context.xml file that you have indicated – Biju Kunjummen Sep 26 '12 at 16:38
  • You were correct, I found the correct file. I am trying ti test if it works on windows but I am not geting the image to load here is my entry Not sure if I am doing it correct. – Faiyet Sep 26 '12 at 17:44
  • 1
    No, `classpath:` with a file system path will not work, if you have it in filesystem try this instead `file:/C:/Users/faiyo/Pictures/` – Biju Kunjummen Sep 26 '12 at 18:28