本來(lái)想用網(wǎng)頁(yè)直接打開(kāi)的,想避免彈出框框來(lái)提示是保存還是打開(kāi),但是我還是選擇了后者,直接用ActiveX太慢了,不知道為什么,用靜態(tài)頁(yè)面都很快,其實(shí)pdf生成文件也很快,不知道為什么放在一起就和蝸牛似的。如果有人知道告訴我是哪里的問(wèn)題,不禁感謝~~
本來(lái)應(yīng)該更早些更新的,這個(gè)問(wèn)題解決了好久,還是寫(xiě)上來(lái)吧,其實(shí)很簡(jiǎn)單。因?yàn)閜df還沒(méi)有完全生成好,我的servlet已經(jīng)打開(kāi)這個(gè)頁(yè)面,而這個(gè)頁(yè)面直接去打開(kāi)pdf ,所以會(huì)很慢,而且網(wǎng)頁(yè)不自己刷新,后來(lái)想到如果頁(yè)面的javascript報(bào)錯(cuò),我就刷新頁(yè)面,結(jié)果ok了。速度還是比較好的。
網(wǎng)頁(yè)版的:
<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();
}
}
本來(lái)應(yīng)該更早些更新的,這個(gè)問(wèn)題解決了好久,還是寫(xiě)上來(lái)吧,其實(shí)很簡(jiǎn)單。因?yàn)閜df還沒(méi)有完全生成好,我的servlet已經(jīng)打開(kāi)這個(gè)頁(yè)面,而這個(gè)頁(yè)面直接去打開(kāi)pdf ,所以會(huì)很慢,而且網(wǎng)頁(yè)不自己刷新,后來(lái)想到如果頁(yè)面的javascript報(bào)錯(cuò),我就刷新頁(yè)面,結(jié)果ok了。速度還是比較好的。
網(wǎng)頁(yè)版的:









PDF1.SetShowToolbar(true);

sevlet版的:這個(gè)就比較簡(jiǎn)單了。







































