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

JSP
搭建Eclipse+MyEclipse开发环境
卖jsp编程技巧的那个垃圾的所有实例的答案全部已收集,现将他人收集的实例答案公布出来,大家鉴赏!
一个jsp+AJAX评论系统
JSP 多个文件打包下载代码
JSP 动态树的实现
jsp 重复提交问题
J2ME/J2EE实现用户登录交互 实现代码
访问JSP文件或者Servlet文件时提示下载的解决方法
JSP EL表达式详细介绍
JSP 报表打印的一种简单解决方案
jsp 自定义标签实例
AJAX自学练习 无刷新从数据库后台取数据显示
AJAX 自学练习 请求与显示
AJAX 自学练习 无刷新提交并修改数据库数据并显示
jsp 文件上传浏览,支持ie6,ie7,ie8
JSP application(return String)用法详例
jsp form表单方法示例
JSP request(return String)用法详例
JSP forward用法分析实例代码分析
JSP JavaBean的setProperty属性

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


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