Solved

Display blob JSP that mimics ASP

Posted on 2009-04-11
1
291 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
issue with pdf generation 2 85
J2SE 5.0 metadata 1 52
Java Exception example issues 11 84
maven project jars 7 50
Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
The new Gmail Phishing Scam going around is surprising even the savviest of users with its sophisticated techniques. This attack comes as a nightmare trifecta for email filtering services; sent from a familiar contact, using authentic tone and verbi…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

864 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