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::
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.
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:
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..
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.