• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to retreive an image from server location

 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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]
 
Srinath Gamage
Ranch Hand
Posts: 40
Google App Engine Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i had the same prob and my solution was to load image in an iframe.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64716
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't just mix the text in with the image stream.
 
Srinath Gamage
Ranch Hand
Posts: 40
Google App Engine Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic