本來想用網頁直接打開的,想避免彈出框框來提示是保存還是打開,但是我還是選擇了后者,直接用ActiveX太慢了,不知道為什么,用靜態頁面都很快,其實pdf生成文件也很快,不知道為什么放在一起就和蝸牛似的。如果有人知道告訴我是哪里的問題,不禁感謝~~
本來應該更早些更新的,這個問題解決了好久,還是寫上來吧,其實很簡單。因為pdf還沒有完全生成好,我的servlet已經打開這個頁面,而這個頁面直接去打開pdf ,所以會很慢,而且網頁不自己刷新,后來想到如果頁面的javascript報錯,我就刷新頁面,結果ok了。速度還是比較好的。
網頁版的:
<object classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" name="PDF1" width="100%" height="633" border="0">
<param name="_Version" value="65539">
<param name="_ExtentX" value="20108">
<param name="_ExtentY" value="10866">
<param name="_StockProps" value="0">
<param name="SRC" value="真正的路徑">
</object>
<script language="JavaScript">
if(typeOf(PDF1)=="undefined"){ location.reload(); }
PDF1.SetShowToolbar(true);
</script>
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String name = request.getParameter("name") == null ? "" : request.getParameter("name");
String path = request.getParameter("path") == null ? "" : request.getParameter("path");
String inPdfName = path + "pdf\\" + name + ".pdf";
String realPath = this.getRealPath(path);
String xmlSourceFile = realPath + "xml\\" +name+ ".xml";
realPath += "pdf\\";
File dirs = new File(realPath);
String outputFile = realPath + name + ".pdf";
ServletOutputStream out =response.getOutputStream();
response.setContentType("application/pdf");
response.setHeader("Content-disposition","attachment; filename="+name+ ".pdf");
BufferedOutputStream bos = null;
try{
FileInputStream fis = new FileInputStream(new File(outputFile));
bos = new BufferedOutputStream(out);
byte[] buff = new byte[8192];
for (int i=fis.read(buff); i>0; i=fis.read(buff))
{
bos.write(buff, 0, i);
}
if(bos!=null) bos.close();
}catch(Exception e){
}
finally {
if (bos != null)
bos.close();
}
}
本來應該更早些更新的,這個問題解決了好久,還是寫上來吧,其實很簡單。因為pdf還沒有完全生成好,我的servlet已經打開這個頁面,而這個頁面直接去打開pdf ,所以會很慢,而且網頁不自己刷新,后來想到如果頁面的javascript報錯,我就刷新頁面,結果ok了。速度還是比較好的。
網頁版的:









PDF1.SetShowToolbar(true);

sevlet版的:這個就比較簡單了。







































