wood burning stoves 2.0*
The moose likes JSP and the fly likes Image is not displayed on the JSP page. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Image is not displayed on the JSP page." Watch "Image is not displayed on the JSP page." New topic
Author

Image is not displayed on the JSP page.

Aryan naresh
Greenhorn

Joined: Oct 06, 2011
Posts: 6
Hi Ranchers,

I tried to display an image in my jsp, but it is giving the X symbol instead of the image.
It is printing all the data.. in the servlet.. so the URL is mapped correctly.
Didn't get the solution.. please help.

Home.jsp



LoginServlet.java




DsiplayImgservlet.java



webxml


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61105
    
  66

Welcome to the Ranch!

One things that will help a lot is if you please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information.

Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61105
    
  66

I assume that this is the mage that you are having trouble with?

It looks like you wisely are constructing the URL using server-relative addressing starting with the context path (good job ). That's usually one of the major causes of problems like these, but not in this case.

What I would do next os to cut and paster the generated URL (do a View Source in the browser to see the generated HTML), and paste that URL into the browser address field. Does the image show up? If not, then you know your JSP is not the issue, but the servlet that serves up the image (the one mapped to /getImage).
Aryan naresh
Greenhorn

Joined: Oct 06, 2011
Posts: 6
Thank you Bear, Did as you said..
It didn't show the image. Could you please suggest me, where am i going wrong in my servlet?
I tried the same servlet to test in another application, it worked.
Please suggest , What's going wrong in my code?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

So you are generating a URL which doesn't point to an image, right? What you should do next is to figure out what URL you need instead. That would be the URL which points to the image you expected. Then change your code to generate that URL instead.
Aryan naresh
Greenhorn

Joined: Oct 06, 2011
Posts: 6
Paul Clapham wrote:So you are generating a URL which doesn't point to an image, right? What you should do next is to figure out what URL you need instead. That would be the URL which points to the image you expected. Then change your code to generate that URL instead.


As you might have seen my code, the mapped servlet is being invoked.. it prints the console messages which i wrote in the DisplayImgServlet.
Now what is the correction you want me to do?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61105
    
  66

Paul, he's reading the image out of the DB in a servlet.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61105
    
  66

If the image doesn't show when hitting it directly with the browser, it's not going to work when embedded in a page either.

What do you mean by "it works in another application"?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Aryan naresh wrote:As you might have seen my code, the mapped servlet is being invoked...


Actually, I didn't see your code. Or more precisely, I did see it but didn't want to look at it because it was unformatted and hard to read.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61105
    
  66

I went ahead and added code tags to your post. See how much easier the code is to read? In the future, if you want people to read your code, please use code tags to make it readable.
Aryan naresh
Greenhorn

Joined: Oct 06, 2011
Posts: 6
Thank you Bear for adding the code tags.
I developed one more application to display image.
There also i used the same code, it displayed the image successfully.
Don't know what's the problem over here.
Gopakumar Naryanan
Ranch Hand

Joined: Jan 15, 2011
Posts: 72

If the console messages are being printed, Then why not the image?
I couldn't see anything wrong in this code.
Are you getting any Exception messages?


Thanks & Regards
Gopakumar
Aryan naresh
Greenhorn

Joined: Oct 06, 2011
Posts: 6
There are no Exception messages.
Still the image is not being displayed.
I think there is a minor mistake, which i'm not able to findout.
Can anybody , suggest what are the possibilities for this kind of issues?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61105
    
  66

Use a debugging tool in the browser to carefully inspect the response when you type the image URL directly into the browser. Are the headers correct? Is the length of the body correct? If all that is correct and the image is still not displayed, the most likely cause at that point is corruption of the image data.
Aryan naresh
Greenhorn

Joined: Oct 06, 2011
Posts: 6
Thank you all.
Bear , what you said is correct.. There is some problem with the table, i used for saving the image.
I tried with another table. It Successfully displayed the image.

The problem might be with

PreparedStatement's setBlob() in inserting the image into table.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Image is not displayed on the JSP page.