• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

how to retrieve image in jsp page from a seperate folder.

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello everybody,
I am in an acute problem, i will be grateful if anyone can help me.

i need to display image in the ".jsp" page. i have created a folder called "image" in the web folder of my project. in the image folder i am storing all the image.

in my database there is one column "ma_image", here i am stroring the filename of the image, say in my "image" folder the image name is "house.bmp" and in the database i am storing "house.bmp" in the "ma_image" column. i am just typing the name of image along with the full extension, i am not using any OLE object to store the image.

now i want to display the image after retrieving it from the "image" folder of my project. the location of "image" folder is:- E:\HomeJsp\web\image

my code is like this::

String path="image/";
//String path="E:/HomeJsp/web/image/";

out.println("<tr><td class=\"menu_tdtd\">Image: </td> <td class=\"menu_td\" id='macImage"+f+"'> </td></tr>");
// out.println("image displayed:-:"+path+"msg");

But i am not getting the image. my output is the filename of the image like-- "home.jsp" it is written in the <td> tag of the browser.

please get me a solution to this problem as soon as possible.

Thanks in advance.
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are using out.println() is a JSP to emit HTML?

Firstly, there should be no Java code in a JSP at all. And the whole purpose of a JSP is to server as template for HTML, so putting the HTML inside a string, inside Java, is complete inside-out.

You really need to update your JSP knowledge.

That said, you cannot use a file path to reference your image. The file path only makes sense on the server machine and has no meaning once the HTML has been served to a client.

You need to either:
  • Put the image file somewhere that it can be served via a URL.
  • Write a servlet that can read the file from disk and stream it as a response.
  •  
    Ranch Hand
    Posts: 78
    Eclipse IDE Tomcat Server Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    You need to either:
    # Put the image file somewhere that it can be served via a URL.
    # Write a servlet that can read the file from disk and stream it as a response.



    Wht to write a servlet code for this ??? i think the jsp itself gets converted to servlet..so why write a seperate servlet code for this..
     
    Bear Bibeault
    Sheriff
    Posts: 67754
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    jas preet wrote: i think the jsp itself gets converted to servlet..so why write a seperate servlet code for this..


    What happens to the JSP is completely irrelevant. It's the URL of the <img> tag that matters.

    And if the image is not addressable by URL, then the way to fetch it is to have a servlet (that does have a URL) fetch and stream the image as its response.

    The easiest solution is, of course, to simply move the image to somewhere that it can be served by the server.
     
    Don't get me started about those stupid light bulbs.
    reply
      Bookmark Topic Watch Topic
    • New Topic