aspose file tools*
The moose likes JSP and the fly likes Display image on jsp page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Display image on jsp page" Watch "Display image on jsp page" New topic
Author

Display image on jsp page

Shuchi Vishnoi
Greenhorn

Joined: Sep 05, 2009
Posts: 6
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

Joined: Mar 22, 2000
Posts: 12825
    
    5
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

Joined: Sep 05, 2009
Posts: 6
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

Joined: Oct 27, 2009
Posts: 43
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

Joined: Sep 05, 2009
Posts: 6
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

Joined: Mar 22, 2000
Posts: 12825
    
    5

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

Joined: Sep 05, 2009
Posts: 6
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

Joined: Mar 22, 2000
Posts: 12825
    
    5
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Display image on jsp page