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

Display image on jsp page

 
Shuchi Vishnoi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to display image on jsp page with some text output. This image is already saved at a location parallel to web-inf and is generated dynamically using a servlet. I have used img tag html to display the image. Other outputs are taking their values from database.
First problem is that image will be taking time to display in comparision of other outputs from database. I have to refresh the page to get image on my page.
Second is that if I save image in a folder parallel to web-inf in my project then it will not be displaying the image.
Can I use any jsp functionality to display image with other outputs from database. I have used "include". but it shows only that image and not other outputs.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. yes, image creation can be time consuming but I bet it is the database side that is really taking lots of time.
2. you should not have to refresh the page if the image file is complete when the IMG request executes
3. see the well known rules in the servlet API about which directories can and can't be directly accessed by the web server.
4. there is no short cut, HTML requires a separate request to load the image

Bill
 
Shuchi Vishnoi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William Brogden wrote:1. yes, image creation can be time consuming but I bet it is the database side that is really taking lots of time.
2. you should not have to refresh the page if the image file is complete when the IMG request executes
3. see the well known rules in the servlet API about which directories can and can't be directly accessed by the web server.
4. there is no short cut, HTML requires a separate request to load the image

Bill


Sir, the data stored in database is not taking time; it displays immediately. Here I am generating image dynamically using a servlet which will be stored in a folder parallel to web-inf. I am using img tag to display image on jsp page with data stored in database, not generating it.
Sir I want to ask that if image is already generated in a relative path of project and called on jsp page using img tag, then why is it taking time to display? Is it because of that fourth point you have written in your reply?
 
suchit pandya
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your image is of larger size or there are many image on the page of large size then also it may take some more time. Generally in such applications on jsp pages image of smaller size like 10 kb, 5 kb are being used.
 
Shuchi Vishnoi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
suchit pandya wrote:If your image is of larger size or there are many image on the page of large size then also it may take some more time. Generally in such applications on jsp pages image of smaller size like 10 kb, 5 kb are being used.


I am using image size of 15-20 kb. there is only single image on that page with some output from database.

 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Well, lets try to isolate the various factors.

You say that DB delay is not significant for the text part of the HTML page presentation.

Suppose you create a static HTML page that uses the same IMG tag pointing to an existing jpg file - does it also take a similar delay to load?

Bill
 
Shuchi Vishnoi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William Brogden wrote:
Well, lets try to isolate the various factors.

You say that DB delay is not significant for the text part of the HTML page presentation.

Suppose you create a static HTML page that uses the same IMG tag pointing to an existing jpg file - does it also take a similar delay to load?

Bill


Sir, here I can't use a html page. Images are generated and stored dynamically in a folder parallel to web-inf with a dynamic name having userID(userID.png). All images are different from each other and having different name.
To display a user's generated image(graph) on jsp page dynamically I am using IMG tag and in src of IMG tag I have to write an expression which is getting that userID(<%= userID %>).png.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apparently you don't understand what I am saying.

Since a complete web application is made up of many parts, in order to debug/optimize a web application we must be able to isolate the various factors. You don't try to solve the whole thing in one go.

My suggestion with the static html page and static jpg image would isolate the image file serving and browser rendering time from all the other complicating factors.

Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic