Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Pro JSP
|
Pro JSP Advanced JSP coding questions. Beginning questions will be redirected to the Beginning JSP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro JSP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 20th, 2011, 05:19 PM
Registered User
 
Join Date: Jan 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by lapog View Post
I am trying to write an application which can upload and download files [Excel, Word etc.] to/from an Oracle 9i database Blob field. I am using Java/JSP for the same.

The upload part works just fine. However, when I try to download the file that I uploaded, I get an error.

A dialog box comes up asking me to Open/Save the file. However, when I try to save it, it says

“Internet Explorer cannot download …..tion=download&planId= testplan from localhost

Internet Explorer was not able to open this Internet Site. The requested site is either unavailable or cannot be found. Please try again later.”


I am using IE 6.0. I tested the same with Firefox browser and was able to download the file.

Can anyone help?

Code:

Following is the code I am using for the same.




/* Code to retrieve from Blob field */

String sqlString = "SELECT PLAN_DOCUMENT_NAME,PLAN_DOCUMENT FROM BRS_PLAN_DESCRIPTION WHERE PLAN_ID = ?";

ps = con.prepareStatement(sqlString);
ps.setString (1,planId);
rs = ps.executeQuery();
while (rs.next()) {
fileBytes = rs.getBytes("PLAN_DOCUMENT");
fileName = rs.getString("PLAN_DOCUMENT_NAME");
}

brsPlanDocument.setPlanId(planId);
brsPlanDocument.setFileName(fileName);
brsPlanDocument.setFileBytes(fileBytes);



/* Code for download */

String fileName = brsPlanDocument.getFileName();
String fileType = fileName.substring(fileName.indexOf(".")+1,fileNam e.length());


if (fileType.trim().equalsIgnoreCase("txt"))
{
response.setContentType( "text/plain" );
}
else if (fileType.trim().equalsIgnoreCase("doc"))
{
response.setContentType( "application/msword" );
}
else if (fileType.trim().equalsIgnoreCase("xls"))
{
response.setContentType( "application/vnd.ms-excel" );
}
else if (fileType.trim().equalsIgnoreCase("pdf"))
{
response.setContentType( "application/pdf" );
}
else if (fileType.trim().equalsIgnoreCase("ppt"))
{
response.setContentType( "application/ppt" );
}
else
{
response.setContentType( "application/octet-stream" );
}

response.setHeader("Content-Disposition","attachment; filename=\""+fileName+"\"");
response.setHeader("cache-control", "no-cache");

byte[] fileBytes=brsPlanDocument.getFileBytes();

ServletOutputStream outs = response.getOutputStream();
outs.write(fileBytes);
outs.flush();
outs.close();

Can anyone tell me what is this brsPlanDocument object ?





Similar Threads
Thread Thread Starter Forum Replies Last Post
BLOB: file is empty after retrieving blob data thr taraprasad Pro JSP 0 May 22nd, 2008 10:02 AM
Download file -JSP gagsy Pro JSP 0 February 28th, 2008 06:08 AM
BLOB from jsp upen Java Databases 0 October 30th, 2006 09:35 AM
upload a xls file into database blob column gummadis Pro VB Databases 0 September 14th, 2004 12:12 PM
BLOB field file types kend SQL Server ASP 0 December 19th, 2003 02:45 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.