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.
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
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
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.
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)
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.
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
Sorry to say but images are displayed only on localhost
Not on other machines
Bauke Scholtz
Ranch Hand
Joined: Oct 08, 2006
Posts: 2458
posted
0
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.
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
Joined: Oct 08, 2006
Posts: 2458
posted
0
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.
amit daundkar
Ranch Hand
Joined: Jan 24, 2009
Posts: 47
posted
0
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.