Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display IMG from Blob database field ?

 
Franck Tranchant
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there

I would like to create a JSP where the user can click and display a picture in a new browser window.

Pictures are stored in database as BLOBs.
I succesfully managed to code this in a servlet with a simple BufferedOutputStream straight forward the HttpServletResponse as a new window.

The problem is that i cannot handle the window size according to the image's real size... The browser (IE) use a default size. Far too big most of time

Does anyone know a trick to specify the size of the new window ?
Or maybe there is another way to solve the problem...

Notes :
- I don't know the size of the image before the user click on the link
- I need to handle a binary Stream since I don't have possibility to store the picture as temporary file on the server

Thanx in advance
[ December 02, 2004: Message edited by: Franck Tranchant ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64713
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll assume that you are showing the image via an <img> tag that references the servlet that fetches the image from the DB.

In order to open a window of a specific size, you must use the Javascript window.open() method, and must know the dimensions you want.

So here's one approach:

1) When the link is clicked, a request is submitted to a hidden iframe on the page. This way, you can submit something to the server without changing the current page.

2) The "hidden" request looks up the size of the image to be displayed and returns a response that contains the Javascript necessary to open the new window to the size you desire.

3) The URL specified for the new window references a JSP that contains the <img>tag that displays the image.

Using this method you need two server trips per image: one to look up the size and one to actually display the image.
 
Franck Tranchant
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I solved this issue using another approach :

Instead of providing the user a link pointing on the Servlet (<A TARGET="_blank" HREF="retrievePicture?someParam=xxx">) , I provide a link pointing on a JSP.

In this JSP, the HTML tag <IMG> is included similar to this one : <IMG SRC="retrievePicture?someParam=xxx">

Using a simple JavaScript code, I can easily resize the window size according to the IMG size...
[ December 06, 2004: Message edited by: Franck Tranchant ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic