1

I have one java rest web service that is deployed on Tomcat 8 Server, this Tomcat 8 is installed on Ubuntu Server.

My java rest web service work is that it save images into the below location

/opt/tomcat/webapps/TestWebService/WEB-INF/image/xyz.image

Images are successfully save on above location

But i want to access these images via url like

http://192.168.1.185:8080/TestWebService/WEB-INF/image/xyz.image

So how can i do this?

I am using Tomcat 8 and Java.

user3441151
  • 1,880
  • 6
  • 35
  • 79
  • You write a servlet that reads the data as a bytestream. You simply use the servlet URL in a html img element. Similar to [this answer that reads the img data from database](http://stackoverflow.com/a/2341322/744133). – YoYo Jul 15 '16 at 14:37
  • 1
    Another way is to modify the `server.xml` as [exemplified in another answer](http://stackoverflow.com/a/1812356/744133) to include the path of your images within the context of your webapp. – YoYo Jul 15 '16 at 14:45
  • Don't expose the contents of your WEB-INF folder. Place the images in a resources folder, or some other folder within your web application itself. – ManoDestra Jul 15 '16 at 22:11

1 Answers1

1

The specification of Java Web Containers doesn't allow implementors to serve files inside of WEB-INF folder. If you want Tomcat to serve the image content, put the files outside WEB-INF folder.

/opt/tomcat/webapps/TestWebService/image/xyz.image

You can access it via

http://192.168.1.185:8080/TestWebService/image/xyz.image
DiogoSantana
  • 2,404
  • 2
  • 19
  • 24
  • I change my code and image is created on "/opt/tomcat/webapps/TestWebService/images/20160718195340.png" successfully but when i access "http://192.168.1.185:8080/TestWebService/images/20160718195340.png" page is blank. – user3441151 Jul 18 '16 at 14:53