aspose file tools*
The moose likes Servlets and the fly likes how to retreive an image from server location Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to retreive an image from server location" Watch "how to retreive an image from server location" New topic
Author

how to retreive an image from server location

chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

hi everybody, i have a proble. please give a solution for me.

i have a jsp which uploads images to the server from client. i have sucessfully done it with assistance. now the problem is i have to retreive the image from server to client. i have retreived the file. the sample code is



this code is working.

if i am trying to output some text with the image it is not working. only the image is being displayed. text is not being displayed. the sample code is



more over i want the image to be displayed as a link. so i have written the code link this

out.print("<img />");

this code is working sucessfully if the client and server both are the same machine. if the client and serevr are both different machines this code is not working. i understood the problem. but i am unable to fix the problem.


the problems are:
1) i need to get the image as well as the text
2) i need the image to be displayed as a link

[Edit: put code between [code] and [/code] ubb code blocks]


Love all, trust a few, do wrong to none.
Srinath Gamage
Ranch Hand

Joined: Jun 19, 2008
Posts: 40

i had the same prob and my solution was to load image in an iframe.

SCJP & SCMAD
http://srinathbugz.blogspot.com/
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

sir i dont know about iframes. i am new to java. how ever i have sucessfully acheived the task. thank you sir, for your reply. if you want i can send you my solution. i have deployed it on the server and executed from another system. it worked
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

As far as I understand it, this code is serving a .png file. And you are appending "abcdef" to the end of the stream that renders the PNG file. This is like opening a PNG file in a text editor and adding abcdef to the content of the image file. How is this supposed to work?? Also you are using PrintWriter to write a image file but I think you should use ServletOutputStream...

[Sorry, didn't see the problem was solved, I wonder though how it is working]


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60975
    
  65

You can't just mix the text in with the image stream.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Srinath Gamage
Ranch Hand

Joined: Jun 19, 2008
Posts: 40

anusha chaitanya wrote:sir i dont know about iframes. i am new to java. how ever i have sucessfully acheived the task. thank you sir, for your reply. if you want i can send you my solution. i have deployed it on the server and executed from another system. it worked


Do it this way,
1. Add iframe to your jsp like this -
<iframe src ="/image?id=1234" >
</iframe>
+ any other html
2. Handle "/image" in a separate servlet and you can use it to send requested image to iframe.
you can use

So you don't have to bother about image format.
Hope you are clear now
Salil Vverma
Ranch Hand

Joined: Sep 06, 2009
Posts: 253

Hey Anusha ,

To display an image I think <img> is a better option than opening a file and appending byte by byte to the response.
more over i want the image to be displayed as a link. so i have written the code link this

out.print("<img />");

this code is working sucessfully if the client and server both are the same machine. if the client and serevr are both different machines this code is not working. i understood the problem. but i am unable to fix the problem.


just check whether you gave obsulute path of file (in your machine) in <img> tag. In that case, It would not work if you try to access same from other machine. You can tweak the code as mentioned below. it would bring image as well as the text to the browser. The only catch is here that the imge file must be just under the webcontent (root).



Regards
Salil Verma


Regards
Salil Verma
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

hi everybody, thanks for all of you for being with me and suggesting me, now i learned various ways on how to retrieve images, this is all because of you guys....thank you for being with m
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: how to retreive an image from server location