Solved

Display blob JSP that mimics ASP

Posted on 2009-04-11
1
290 Views
Last Modified: 2012-05-06
How could I modify the below JSP to mimic the ASP, so it simply displays the blob without having to write it to a file first?
 
// Display Blob JSP
PreparedStatement ps = MyConn.prepareStatement("SELECT MyBlob FROM MyTable");
ResultSet rs = ps.executeQuery();
if (rs.next()) {
  Blob b = rs.getBlob(1);
  BufferedOutputStream os;
  File f = new File("MyFile.pdf");
  os = new BufferedOutputStream(new FileOutputStream(f));
  os.write(b.getBytes(1,(int) b.length()),0,(int) b.length());
  os.flush();
  os.close();
  out.print("<script language=javascript>self.location.replace('MyFile.pdf');</script>\n");
}
 
' Display Blob ASP
Set rs = MyConn.Execute("SELECT MyBlob FROM MyTable")
If Not rs.EOF Then
  Response.ContentType = "application/pdf"
  Response.BinaryWrite rs("MyBlob")
End If
0
Comment
Question by:arichexe
1 Comment
 
LVL 27

Accepted Solution

by:
rrz earned 250 total points
ID: 24124224
If it is just an image, then you could use something like
       Blob b = rs.getBlob(1);
       InputStream is = b.getBinaryStream();
       byte[] imgData = new byte [(int)b.length()];
       is.read(imgData);
       response.setContentType("image/gif");
       OutputStream o = response.getOutputStream();
       o.write(imgData);
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

A safe way to clean winsxs folder from your windows server 2008 R2 editions
Owning a franchise can be the dream of a lifetime. It provides a chance for economic growth. You can be as successful as you want.  To make your franchise successful, you need to market it successfully. Here are six of the best marketing strategies …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now