• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to display multiple images in the jsp

 
sri ramvaithiyanathan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to display multiple images in jsp page.
imageCategoryId is the primarykey it contain multiple images in the DB[oralce 10g is the database]
kindly tell me how i have to call the servlet from the jsp page and how i have to show the image in jsp page.
And finally whether action and dao files are correct.If its wrong kindly guide me how to solve the problem.







P.S : kindly forgive me if i posted in the wrong column.

Regards,
ram.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how i have to call the servlet from the jsp page


Your IMG tag must specify a URL that points to the image serving servlet and includes the catgId parameter.

I recommend that you start from the simplest test - a static HTML page containing a single IMG tag. When you get that working, then go to JSP. Trying to do everything at once will just be confusing.

Note that image fetching will always be a GET, not a POST.

Bill
 
sri ramvaithiyanathan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi william,

Thanks for your reply.
Is there any other mistake i did in the java code.Any modification i have to do to retrieve multiple image.
Kindly tell me.How to refine the program.
And finally whether i have to do use logic tag in jsp to retrieve multiple image.
How i have to do it in jsp.Please guide me.

Regards,
Ram
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There'll be one image per IMG tag. The only way a JSP page can display multiple images is by creating multiple IMG tags.
 
sri ramvaithiyanathan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lester Burnham wrote:There'll be one image per IMG tag. The only way a JSP page can display multiple images is by creating multiple IMG tags.


the images are dynamic it may be 1 or 5 or 25.
How to keep multiple image tag in jsp.

Is this way is good to use inside jsp
inside loop i use this image tag and i will pass imageid to retrieve it from db.

<img src="myservletName?imageId="+imgId>
But it will hit the DB 'N' number of time.
perfomance wise its not good idea to use.

kindly suggest how to do it in better manner.

P.S : Kindly tell me whether the java codes are correct.
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hardly used wrote:inside loop i use this image tag and i will pass imageid to retrieve it from db.

Yes, that's the basic approach to do this.

But it will hit the DB 'N' number of time.

Not necessarily. You can retrieve the image data for all images once -with a single SELECT statement- and keep them in a session. You may want to keep track of which images have been rendered, so that you can remove the data from the session once they've all been displayed.
 
sri ramvaithiyanathan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did the DAO and it retrieved the image from the DB.
In Action file i wrote the bytes into ByteArrayOutputStream.

After that i have to keep the ByteArrayOutputStream into session and i have to retrieve the image from the byteArrayOutputStream.

This is what my understanding.
If i am wrong kindly tell me how to do this.

Please suggest any good link to that contain information about this.

P.S:Hi guys please tell me whether action and dao files are correct.Any change i have to do in Action and dao file.
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sri ramvaithiyanathan wrote:I did the DAO and it retrieved the image from the DB.
In Action file i wrote the bytes into ByteArrayOutputStream.

After that i have to keep the ByteArrayOutputStream into session and i have to retrieve the image from the byteArrayOutputStream.

Putting streams in the session is not such a good idea. The easiest would seem a List<byte[]>.
 
sri ramvaithiyanathan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all of your efforts guys.
solved this issue using struts2

regards,
ram
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!