Andrew
Andrew

Reputation: 165

Server server static content which is generated dynamically

I have a web app which gets photos via uploading and saves them in a folder called Pictures(which is in /home/andrei/Pictures) and then i want to display them through servlets(within html documents). I heard i had to use a front servlet and that i will have a domain but i did not manage to do it. Could you show me how to do it?

(I saw some ways but i did not get it)

Other information:
OS: Linux Ubuntu
Server: Apache Tomcat v7
IDE: Eclipse

Upvotes: 1

Views: 64

Answers (1)

MaVRoSCy
MaVRoSCy

Reputation: 17839

here is a complete example of how you can use Servlets to expose an image to your client http://www.exampledepot.com/egs/javax.servlet/GetImage.html

The modification you have to do is here:

String filename = sc.getRealPath("image.gif");

You just have to include the fullpath yo your image...

Good Luck!

UPDATE

You can display the image in html using:

<img src="/ServletName?id=xxxx" ... ... ... />

This, will cause the browser to make an http request to your servlet with < url-pattern > = ServletName and fetch the image with id=xxxx to the client browser

Upvotes: 2

Related Questions