1)我想下載一個存儲在oracle數據庫中的pdf文件作爲blob。但我得到0 kb文件。 我沒有這樣做過。所以請在按鈕上點擊幫助 一個servlet調用另一個做下載工作的servlet。 這是我寫的下載文件的代碼。下載blob後沒有數據pdf文件
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,fileName.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();
}
}
ServletOutputStream outs = response.getOutputStream();
outs.write(fileBytes);
outs.flush();
outs.close();
請告訴我我哪裏出了問題。如何下載帶有數據的完整pdf文件?
2)假設這個pdf文件是客戶details.lets的完整報告.lets假設它有300頁。併爲每個客戶瞭解頁碼。前客戶安東尼他的頁面沒有在這個pdf是4和5.我只想下載這2頁的文件。我可以如何完成這項任務?
UPDATE: jtahlborn解決這是很愚蠢的我的第一個問題......只是要添加以下代碼行
resp.getOutputStream().write(fileBytes);
resp.getOutputStream().flush();
resp.getOutputStream().close();
所以最後與成功。現在,請幫助我解決第二個問題。我想從pdf下載頁面,並將其保存爲單獨的pdf文件。其實這是我想下載的PDF。不是第一個pdf。我只是這樣做來學習下載一個blob文件。
問你的第二個問題作爲一個單獨的問題。堆棧溢出是提供問題答案的平臺。但確定正確答案的唯一方法是每個線程都有一個問題。 – APC 2012-02-23 14:07:27