Solved

Display blob JSP that mimics ASP

Posted on 2009-04-11
1
296 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Multi-threading long-running processes can have a significant increase in overall performance and drastically decrease over time it takes for a process to complete. Unfortunately, not all applications support native multi-threading, some by design a…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

705 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