Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

img tag does not display image

 
Varun Nayudu
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am using trying to display an image on my starting screen but i am not able to see the image on the browser. The Jpg image file and the jsp in which i want to how the image are in the same folder (web-app/Pro)Pro is my Project name.Bur still i am unable to get the image.

<img src="Header.jsp" height="300"/>

Header.jsp is the jsp in which i want to show the image.
i am using Dreamweaver to make the jsp and it is display the image on it but when i run the tomcat and view the Webpage its giving a blank screen.
[ October 14, 2008: Message edited by: Bear Bibeault ]
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The src attribute of the img tag must point to the image itself (a JPEG, GIF or PNG), not to some other page that in turn shows the image.
 
Varun Nayudu
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i dont want to show only the image i want to show some other things which i am going to pas to that page as parameters. That is why i want to show the JSP page and not the image.
 
Ananth Chellathurai
Ranch Hand
Posts: 349
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A JSP page can not be considered as an image. For displaying a jsp you have to use include.

Regards
Ananth Chellathurai
 
stef li
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it will doesn't work if you set the src to the jsp page if the jsp page doesn't return am image stream.

if you want to show the pic and contain some other params, i suggest you to use iframe.
 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It turns out (much to my amazement) that you can actually have the src parameter of an image tage point off to another jsp.

Have a look at using a jsp to output a binary stream and an example of why you might want to do this.
[ October 14, 2008: Message edited by: Rachel Swailes ]
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can actually have the src parameter of an image tage point off to another jsp

That's not a good idea. It may work in certain circumstances, but there are servlet containers where it simply will not work. You just shouldn't use JSPs for binary content. It's bad design to have Java code in JSPs, anyway.
 
Mark Smith
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What would be the correct way to display dynamically created images in a java servlet?
 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf, I agree that this probably isn't the best way to accomplish this. I was just commenting that (while it's not a brilliant way to go about it) it is technically possible.

And I completely agree that Java code in jsp's is a very bad design!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mark Smith:
What would be the correct way to display dynamically created images in a java servlet?
The <img> tag's src should reference a servlet (not a JSP, never a JSP) that streams the image data.
 
Nicola Seidita
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
I use a servlet to get image data from db and write image on page.
on tomcat it runs very well but on OAS it doesn't works.
I think that i need to set something like url-patterns in web.xml
but I can't find out what.
Any ideas?

thanks in advance
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic