Solved

Display blob JSP that mimics ASP

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Struts tiles for layout structure along with Angular JS. 4 172
project group option in netbeans equivalent term in eclipse 1 51
parse example 13 95
by zero exception 10 53
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Ransomware is a malware that is again in the list of security  concerns. Not only for companies, but also for Government security and  even at personal use. IT departments should be aware and have the right  knowledge to how to fight it.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

820 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