1.I want to download a pdf file which is stored in the oracle db as a blob. But i get 0 kb file.
I havent done this before. So pls help
on button click a servlet calls another servlet which does the job of downloading.
This is the code i wrote to download the file.
protected void processRequest(HttpServletRequest request, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("text/html;charset=UTF-8");
try {
OutputStream outStream = resp.getOutputStream();
List file=(List)request.getAttribute("file");
String fileName=null;
byte[] fileBytes=null;
for (int i=0;i<file.size();i++)
{
Map objec=(Map) file.get(i);
fileName=(String)objec.get("fileName");
fileBytes=(byte[])objec.get("fileBytes");
}
String fileType = fileName.substring(fileName.indexOf(".")+1,fileNam e.length());
if (fileType.trim().equalsIgnoreCase("pdf"))
{
resp.setContentType( "application/pdf" );
}
resp.setHeader("Content-Disposition","attachment; filename=\""+fileName+"\"");
resp.setHeader("cache-control", "must-revalidate");
System.out.println(fileBytes);
} finally {
// out.close();
}
}
Please tell me where i went wrong.How can i download the full pdf file with data?
2. Lets say this pdf file is a full report of customer details.lets assume its got 300 pages. and for each customer the page no's are known. ex for customer Antony his page no in this pdf is 4 and 5. I want to only download the file with these 2 pages.How can i accomplish this task?
UPDATE:I solved my first problem which was very silly...just had to add the following lines
resp.getOutputStream().write(fileBytes);
resp.getOutputStream().flush();
resp.getOutputStream().close();
So i finally succeeded with that. Now pls some1 help me for my second problem.I want to download pages for which page no's are known from the pdf and save as a separate pdf file. Actually thats the pdf i want to download. Not the first pdf. I just did that to learn to download a blob file.