说明:文件unload.js在js目录下,文件unload_excel.jsp和unload_word.jsp在unload目录下。
1,unload.js
/**************************************************
作者:云凤生(hainanyun@hotmail.com)
创建日期: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;
}
<%
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%>" />
<%
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%>" />
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器