• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Displaying images on JSP page

 
Ranch Hand
Posts: 643
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to display images on my JSP page .I have images stored on my MySQL database , I am copying those images to c:\ ,the images get displayed correctly on localhost but when I run the same application on other machines images are not getting displayed.

How to store those images as cookies in clients web browser to get it displayed in clients machine also.

Thanks in advance.
Chetan D.
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Search this same section with "JSP display image", this is discussed lots of time.
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

chetan dhumane wrote:the images get displayed correctly on localhost but when I run the same application on other machines images are not getting displayed.


Paste the way you are accessing the images in JSP, and make sure you are not copying "localhost" in URL of images.

chetan dhumane wrote:
How to store those images as cookies in clients web browser to get it displayed in clients machine also.


You really don't need cookies to store images on browser, lets browser cache it for you
 
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

chetan dhumane wrote:.

How to store those images as cookies in clients web browser to get it displayed in clients machine also.

Chetan D.



Thats Strange. Cookies are meant to store client state and information and not for these things.


I am copying those images to c:\ ,the images get displayed correctly on localhost but when I run the same application on other machines images are not getting displayed.



The images has to be inside the webserver directories to be accessible from other machines
 
Ranch Hand
Posts: 164
Android Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The bellow link will help you
webpage
 
chetan deol
Ranch Hand
Posts: 643
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to embed that image into img tag and then display it.
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Balu Sadhasivam wrote:
The images has to be inside the webserver directories to be accessible from other machines

 
chetan deol
Ranch Hand
Posts: 643
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone help me to tell getting images from database and displaying it on JSP page using img tag .
I have also written beans for the same to store the images in the database and to retrieve the recordset using beans.
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks like our efforts goes in vain

OK, still some pointers-

  • Google it, Display images stored into database in a JSP
  • Search the same forum
  • Tell us the details about where you get stuck, form your last reply, I conclude that, you're facing problem in <img src="\path" .../>, for that, Balu suggested about saving image in to web server (If its Tomcat, then store image into "webapps/YOUR_APP/images_from_db/myimage.jpg", for which resulted img tag)

  •  
    chetan deol
    Ranch Hand
    Posts: 643
    Android Eclipse IDE Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I got stuck about getting the images from db and storing it into images folder.
    I am able to store images into MySQL database using BLOB format.But how to get that image and display into the <img> tag of html.
    I want my JSP page to store those images automatically to images folder of my webapp at runtime.

    I dont want to set contentType to images/jpg ,It causes to "display an message box about downloading the particular image"
    I think you got my question.

    I also want to display multiple images on single page.

     
    Sagar Rohankar
    Ranch Hand
    Posts: 2908
    1
    Spring Java Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    chetan dhumane wrote:I got stuck about getting the images from db and storing it into images folder.




    This is general idea, please check out the API for correct methods.

    JSP
     
    chetan deol
    Ranch Hand
    Posts: 643
    Android Eclipse IDE Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    But when I access my project URL from another machine ,images do not get displayed.
    I can see images on my localhost only.
     
    Sagar Rohankar
    Ranch Hand
    Posts: 2908
    1
    Spring Java Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Just paste the JSP code you're using to display images.
     
    chetan deol
    Ranch Hand
    Posts: 643
    Android Eclipse IDE Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
     
    Sagar Rohankar
    Ranch Hand
    Posts: 2908
    1
    Spring Java Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    You couldn't get access to this c: drive when you access the image from another machine, better way is to store this image relative to the project folder, like

    Try this.
     
    chetan deol
    Ranch Hand
    Posts: 643
    Android Eclipse IDE Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    What is l:\
     
    Sagar Rohankar
    Ranch Hand
    Posts: 2908
    1
    Spring Java Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    typo



     
    chetan deol
    Ranch Hand
    Posts: 643
    Android Eclipse IDE Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Sorry to say but images are displayed only on localhost
    Not on other machines
     
    Ranch Hand
    Posts: 2458
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    You're doing it the wrong way. Above all, writing raw Java code in a JSP file is absolutely a bad practice. Never do that.

    You need a servlet which reads the InputStream of the image from the database and writes it to the OutputStream of the response.

    Then you invoke that servlet in the <img src>. You should not use absolute file system paths, that would only work if the server runs at the same machine as the client. Simply because of the fact that the client is the one which should request for images. If it encounters a file system path, then it will lookup the image in its disk file system. This isn't going to work if the image is located at the disk file system of the server machine.

    You can find here an example how to do it the right way: http://balusc.blogspot.com/2007/04/imageservlet.html (this article consits of 2 examples, you need to scroll down for the database example).
     
    chetan deol
    Ranch Hand
    Posts: 643
    Android Eclipse IDE Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks
     
    chetan deol
    Ranch Hand
    Posts: 643
    Android Eclipse IDE Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    But how that reuest.getPathInfo() is working.
    Means how do I call that Servlet from my JSP page what are the required arguments.
     
    Bauke Scholtz
    Ranch Hand
    Posts: 2458
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Do not only copypaste the servlet code, but also read the article's text and the remnant code snippets and examples for web.xml and JSP.
     
    Ranch Hand
    Posts: 47
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    chetan dhumane wrote:I want to display images on my JSP page .I have images stored on my MySQL database , I am copying those images to c:\ ,the images get displayed correctly on localhost but when I run the same application on other machines images are not getting displayed.

    How to store those images as cookies in clients web browser to get it displayed in clients machine also.

    Thanks in advance.
    Chetan D.



    hello chetan,
    please give me that code to retrieve imgage. one that is working on localhost.
     
    Bauke Scholtz
    Ranch Hand
    Posts: 2458
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Did you also read the responses on this topic?
    reply
      Bookmark Topic Watch Topic
    • New Topic