Tomcat external directory mapping

Asked

Viewed 986 times

-1

I have a javaEE application where I use Tomcat 8. In it, I mapped an external folder to save the images that the user can register on one of my application screens. To do this, I went to the server.xml file of my Tomcat and did the mapping. Everything was working well for a long time, only yesterday, I ended up deleting Tomcat 8 and had to add it again. As a result, I had to redo the mapping configuration in the server.xml file.

When redoing the configuration, simply mapping does not work anymore. I already gave a clear in Tomcat, I already gave a clear and update project in Maven, and nothing. The context of my application is '/Picos' and I can access it through

localhost:8080/Picos

From there, in an attempt to redo the configuration, I went to the Tomcat.xml server and added<Context docBase="C:\Picos\images" path="/images" /> within the tag <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">, and simply when I put the address in the browser localhost:8080/Picos/images/1.png (remembering that 1.png image exists inside C: Picos images folder) I get 404 error.

What I’m doing wrong, since before the crash of deleting the Tomcat server in eclipise, everything was working perfectly. Am I missing any other settings? Any tips? Thank you

1 answer

-1

I solved the problem. I think it is fair to leave the solution here, since many may end up leaving it unnoticed. When I add a project to mu Tomcat server, the line <Context docBase="Picos" path="/Picos" reloadable="true" source="org.eclipse.jst.jee.server:Picos"/> is added to my server.xml. Thus, the context path to map the external directory has to add the context path above. Would look like this <Context docBase="C:\Picos\images" path="/Picos/images" /> and not <Context docBase="C:\Picos\images" path="/images" />

I hope it helps =)

  • It is not recommended to change the server.xml. This configuration may even work to perform tests locally, but in another context it should not be applied. Also, change the docBase of the entire application can cause devastating side effects, since not only the images, but all the application’s Resources will be accessed from that directory. In security matters, s and a user send a JSP instead of an image, it will be able to execute any code on the server.

  • So how would it be the right way?

  • It depends on how your application works, but the simplest way is to install the application normally and create a Servlet to serve the images.

  • Note that this would be different if the images were not registered by an external user.

  • Uploading images are done by users, through an Android app

Browser other questions tagged

You are not signed in. Login or sign up in order to post.