java界面怎么设置标题,使用windows.open打开一个输出流后怎么设置页面title

使用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插件。

不会吧,那这种输出流岂不是都不能指定标题了 ?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值