用户登录
用户注册

分享至

jsp如何导出word

  • 作者: 模棱22124902
  • 来源: 51数据库
  • 2020-04-21

1.如何将JSP页面显示的内容导出到WORD文档

JSP页面显示的内容导出到WORD文档:

<%response.setContentType("application/msword;charset=utf-8");

response.setHeader("Content-Disposition","attachment;filename=test.doc"); //用word打开页面

%>

<html>

<body>

<table>

<tr>

<td>8888</td>

</tr>

</table>

</body>

</html>

2.如何将JSP页面显示的内容导出到WORD文档

JSP页面显示的内容导出到WORD文档:

<%response.setContentType("application/msword;charset=utf-8");

response.setHeader("Content-Disposition","attachment;filename=test.doc"); //用word打开页面

%>

<html>

<body>

<table>

<tr>

<td>8888</td>

</tr>

</table>

</body>

</html>

3.jsp导出到word

jsp输出word 在页面直接打开word。

在Action中写 response.reset(); response.setContentType("application/msword;charset=utf-8"); response.setHeader("Content-Disposition", "inline;filename=temp.doc");response.getOutputStream().write(document.getContent()); response.getOutputStream().flush(); response.getOutputStream().close();return null;在页面时下载word。 在Action中写 response.reset(); response.setContentType("application/x-download;charset=utf-8"); response.setHeader("Content-Disposition", "attachment;filename=temp.doc");response.getOutputStream().write(document.getContent()); response.getOutputStream().flush(); response.getOutputStream().close();return null;。

4.jsp导出到word

jsp输出word

在页面直接打开word。

在Action中写

response.reset();

response.setContentType("application/msword;charset=utf-8");

response.setHeader("Content-Disposition", "inline;filename=temp.doc");

response.getOutputStream().write(document.getContent());

response.getOutputStream().flush();

response.getOutputStream().close();

return null;

在页面时下载word。

在Action中写

response.reset();

response.setContentType("application/x-download;charset=utf-8");

response.setHeader("Content-Disposition", "attachment;filename=temp.doc");

response.getOutputStream().write(document.getContent());

response.getOutputStream().flush();

response.getOutputStream().close();

return null;

5.怎样设置jsp生成word文档以页面视图来显示

1-apache的POI,此方法对Excel的导出做的很好,目前对Word的导出方面的功能尚未完全。

2-纯JavaScript脚本实现。主要通过客户端调用本机Office组件来实现。

3-在JSP页面引入头文件实现。纯JavaScript脚本实现细节方面大体是创建一个word组件ActiveXObject('Word.Application'),用js通过表ID取得表内容然后保存到word,要注意的是js实现有很多不好的地方,例如Internet选项需要把ActiveX空间全部启用,安全级别设置为中。

这样的话岂不是每台机器都要配置一下。其次每次生成word文档以后弹出对话框(无法保存此文件,因为它已在别处打开(C:\。

\STARTUP\Powerword.dot)),出现此问题就需要把C:\Documents and Settings\当前用户名\Application Data\Microsoft\Word\STARTUP下的Powerword.dot文件删除,每次遇到此问题就需要删除文件来解决,十分不方便。JSP页面引入来实现Word保存就方便多了,但是也有不足的地方,首先如果需要引入

在Action里直接写如下代码:if(out!=null){String fileName=;fileName+=评价报告.doc;try {HttpServletResponse response = ServletActionContext.getResponse();response.setHeader(Content-disposition,attachment; filename=+new String(fileName.getBytes(GB2312), 8859_1));} catch (UnsupportedEncodingException e) {e.printStackTrace();}out是jsp页面表单元素,一个button,用于提交表单到相应Action进行Word下载。Action设置jsp页面头文件。

这样每次点击button就可以把相应jsp页面的内容保存到Word中并且支持下载,Word中内容并且是可编辑状态。不足的地方在于由于表内容是动态生成,有的需要先查看在下载Word,就需要另外建立一个新JSP页面进行Word下载,当然首先要在struts.xml里配置好页面转向。

新建立的页面传值同查看页面要保持一样。

转载请注明出处51数据库 » jsp如何导出word

软件
前端设计
程序设计
Java相关