• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

View stored blob image in the UI using java

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am storing an image or pdf in the database as blob type.

Now i need to disply the image in the UI.

How to disply the image in the UI screen using java code?

Kindly guide us to proceed further.

Thank you.




 
Sheriff
Posts: 22683
128
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For images it's quite easy. Use ImageIO to convert the binary data into a BufferedImage, then use ImageIcon and JLabel for displaying it.
For PDF files it's harder, but I believe PDF renderer can help you out.
 
ruba sampath
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you. But i am not using swing or applet in my application. Is it possible to display through ServletOutputStream?
 
Rob Spoor
Sheriff
Posts: 22683
128
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure. You need a separate servlet that will a) set the right content type, b) if possible, set the content size, and c) include only the image / PDF file data and no other data (like leading / trailing whitespace). The latter makes JSP pages not very good for binary data like images or PDF files, as it's really easy to accidentally add leading whitespace. If you decide to use a JSP page, make sure that there are no line breaks whatsoever outside of the JSP tags - not even between directives.
 
ruba sampath
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much. Its working now. But how to restrict only upload images and pdf and not other types.
 
Rob Spoor
Sheriff
Posts: 22683
128
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe that in HTML5 you can specify file extensions to filter on, but in HTML4 and before you can only refuse to process the files in the form's action page (servlet / JSP / PHP / ...).
 
Don't touch me. And dont' touch this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic