当前位置: 首页 > 图文教程 > 网络编程 > JSP > 把本页内容导出成word文件或excel文件(原创)

JSP
GET 方式提交的含有特殊字符的参数
java big5到gb2312的编码转换
java Lucene 中自定义排序的实现
hibernate中的增删改查实现代码
jsp 定制标签(Custom Tag)
jsp基础速成精华讲解
IE cache缓存 所带来的问题收藏
关于JSP的一点疑问小结
JSP 多条SQL语句同时执行的方法
jsp include文件时的一个乱码解决方法
在JSTL EL中处理java.util.Map,及嵌套List的情况
jsp 页面显示的一些用法
根据Hibernte的cfg文件生成sql文件
五种 JSP页面跳转方法详解
JSP 防范SQL注入攻击分析
JSP 连接MySQL配置与使用
java eclipse 启动参数
jsp 页面上图片分行输出小技巧
解决jsp开发中不支持EL问题
JSP 页面中使用FCKeditor控件(js用法)

JSP 中的 把本页内容导出成word文件或excel文件(原创)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-03   浏览: 220 ::
收藏到网摘: n/a

说明:文件unload.js在js目录下,文件unload_excel.jsp和unload_word.jsp在unload目录下。

1,unload.js
/**************************************************
作者:云凤生([email protected])
创建日期:2005-1-21
最后修改日期:2005-3-30

Function:
1,unload_word():unload local page as word file
2,unload_excel():unload local page as excel file
3,...(waiting for your additional work)

For example:
1,in the head of HTML file,include this file:
<script src="js/unload.js" type="text/javascript"></script>
2,add unload button:
<input type="button" value="导出为Word文档"  name="download" onclick="unload_word(location.href)" >
<input type="button" value="导出为Excel文档" name="download" onclick="unload_excel(location.href)" >
**************************************************/
function unload_word()
{
   var url=location.href;
   location.href='unload/unload_word.jsp?url='+url;
}

function unload_excel()
{
   var url=location.href;
   location.href='unload/unload_excel.jsp?url='+url;
}




2,unload_excel.jsp
<%
   response.setHeader("Content-disposition","attachment; filename=print_tmp.xls");
%>
<%@ page contentType="application/vnd.ms-excel; charset=gb2312"%>
<%@ page import="java.net.URL"%>

<meta http-equiv="Content-Language" content="zh-cn">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">

<%
String url_target = new String(request.getParameter("url"));
String filename = new String();

URL url = new URL(url_target);
filename = url.getFile();
%>

<jsp:include page="<%=filename%>" />




3,unload_word.jsp
<%
   response.setHeader("Content-disposition","attachment; filename=print_tmp.doc");
%>
<%@ page contentType="application/vnd.ms-word; charset=gb2312"%>
<%@ page import="java.net.URL"%>

<meta http-equiv="Content-Language" content="zh-cn">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">

<%
String url_target = new String(request.getParameter("url"));
String filename = new String();

URL url = new URL(url_target);
filename = url.getFile();
%>

<jsp:include page="<%=filename%>" />