使用windows.open打开一个输出流后如何设置页面title
使用windows.open("XXX.do");输出一个pdf文件 如何设置输出页面的title?
try {
String _url = WebUtils.getRealPath(request.getServletContext(), "/upload/temp/" + FileUtils.newFileName("1.pdf")); // 文件地址
this.createCollectFeePdf(collectFeeId, _url);
ServletOutputStream out = response.getOutputStream();
response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "inline; filename=test.pdf");
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(new File(_url)));
BufferedOutputStream bos = new BufferedOutputStream(out);
byte[] buff = new byte[2048];
int len;
while ((len = bis.read(buff)) != -1) {
out.write(buff, 0, len);
out.flush();
}
bis.close();
bos.close();
} catch (Exception e) {
e.printStackTrace();
}
------解决思路----------------------
var aa = window.open('/servlet/xx');
var aa.document.write("
标题1");试试。。
------解决思路----------------------
如果在父窗口就已经知道子窗口的标题是什么,就可以这样写啊:
var myWindow = window.open("xxx.do");
myWindow.document.title="这里写个标题";
我以为楼主是要动态读取服务端PDF文件名作为标题呢。
引用:Quote: 引用:这是个不错的问题,赞一个,但我不会,讨论一下思路吧:
如果XXX.do没有相应的jsp视图,那么就windows.open()后的新窗口完全由浏览器控制,是无法指定页面标题的。
如果有相应的jsp视图页面,而且服务端已经往头里写了文件名:response.setHeader("Content-Disposition", "inline; filename=test.pdf");待文档加载好后,可以用jQuery读取header信息,并将文件名设置为标题(也可在头部自定义标题)。而body中显示流的内容时,建议使用jQuery插件。
不会吧,那这种输出流岂不是都不能指定标题了 ?