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

JSP
JavaBeans 程序开发从入门到精通教程
企业级应用中的Applet和Servlet的通信(一)
企业级应用中的Applet和Servlet的通信(三)
企业级应用中的Applet和Servlet的通信 (二)
Web开发中防止浏览器的刷新键引起系统操作重复提交
谈一下关于XHTML网页的制作
40种网页常用小技巧(javascript)←↓------[不时之需]
使用xmlhttp和Java session监听改善站内消息系统
JSP简明教程:行为标签与实例(转
jsp与javascript的结合在页面间传递参数
最基本的一个转换密码字符串为乱码以及解码的程序
55种网页常用小技巧(javascript)
jsp中标签的部署与调用
用jsp动态输出excel文档和中文乱码问题的解决
J2SDK和TOMCAT的安装及配置
web开发中的多条件查询处理技巧1则
JSP连接Mysql数据库攻略
Tomcat的Servlet配制
JSP/Servlet 中的汉字编码问题
Taglib原理和实现 第五章:再论支持El表达式和jstl标签

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-03   浏览: 198 ::
收藏到网摘: 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%>" />