java web 导出excel

看到这个标题,会很疑问,java导出excel 有很多文章呀,都知道怎么用呀,呵呵,我也是这么认为,我们常用的就是jxl 或者poi ,现在jxl 代码不在更新不支持2007,一般都采用poi 进行excel的操作,今天在看系统(架构struts+ spring+ hibernate),需要做一个excel导出,一个简单的方法,这个方法只适用于excel简单的导出,直接通过输出的页面,然后设置页面为输出流的文件格式,这样当action转向到jsp页面的时候,直接就是将页面输出。

 

jsp页面的代码:

<%@ page language="java" pageEncoding="UTF8"%>
<html:html locale="true">
	<head>   
		<title>LogExport</title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<%
		  response.setCharacterEncoding("UTF-8");
		  response.setContentType("application/vnd.ms-excel;");   
		  response.setHeader("Content-Disposition", "attachment;filename=\""+new String("Log.xls".getBytes(),"ISO-8859-1")+"\"");
		%>  
	</head>
	<body>
		<form action="/Action_export.do">
			<table width="100%" border="1" cellspacing="0" cellpadding="0" id="datagrid">
				<thead>
					<tr class="HeaderStyle" style="font-weight: normal;">
						<th>用户</th>
						<th>姓名</th>
						<th>日期</th>
						<th>登录IP</th>
						<th>主机名</th>
						<th colspan="3">
						 <table width='100%'  border="1" cellspacing="3" cellpadding="0" frame='void' > 
								<tr><td colspan="3" style='background:transparent;' align="center">操作信息</td></tr>
								<tr style='background:transparent;'>
									<td width="40px" align="center">操作</td>
									<td width="100px" align="center">标题</td>
									<td align="center">扩展信息</td>
								</tr>
							</table>
						</th>
					</tr>
				</thead>
				<jsp:include page="common.jsp" flush="true" />
			</table>
		</form>
	</body>
</html:html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值