1.如何在word中打开jsp文件
你的目的是想用word来浏览jsp文件内容吗?似乎没这种必要吧。
如果真想这么做的话,
你可以先通过记事本、editplus等文件编辑工具打开jsp文件,然后复制粘贴到word文档中。
或者,你是想用word作为网页编辑器来打开它?
word可以作为网页编辑器,在打开htm/html静态网页时没问题。
但是对于jsp这种动态类型的网页,它应该是支持得不好,会存在打不开的情况,有的打开了也可能显示不完全。
2.java打印word
步骤:
1,用word编辑你的模板
2,模板保存为html格式
3,在代码中把你要填的值动态拼接到那个html中,
最后
byte[] bytes= bf.toString().getBytes("GBK"); //bf.tostring()得到的拼接后的字符串
response.reset();
response.setContentType("application/msword");
response.setHeader("Content-disposition", "inline; filename=case_print.doc");
response.setCharacterEncoding("GBK");
response.setContentLength(bytes.length);
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);
ouputStream.flush();
ouputStream.close();
3.jsp中 在线打开WORD 修改WORD内容
一种简单的方法是用<iframe name="resource" src="" width="100%" scrolling="auto" frameborder="0"></iframe>,src为word路径,用js设置,这种方法的话,不知道FF支持的如何
还有可以设置response.reset();
response.setContentType("application/x-msword");
response.addHeader("Content-isposition","attachment;filename=" + "C:\\x.doc");
路径也在里面,相对来说要做点工作了
至于保存到服务器可以用smart做上传功能了
我暂时还没想到什么方法可以不重新上传就搞定的。
转载请注明出处51数据库 » owcjspword