把JSP里面的contentType设置为:
contentType="application/vnd.ms-excel; charset=UTF-8"
打开页面的时候就可以直接保存为一个EXCEL文件
代码示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
<%@ page language="java" contentType="application/vnd.ms-excel; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<
html
>
<
head
>
<
base
href="<%=basePath%>">
<
title
>首页</
title
>
</
head
>
<
body
>
<
table
class
=
"table table-condensed table-striped"
>
<
tr
>
<
th
>编号</
th
>
<
th
>班级名称</
th
>
<
th
>班级人数</
th
>
<
th
>开班日期</
th
>
<
th
>结束日期</
th
>
<
th
>操作</
th
>
</
tr
>
<
tr
>
<
td
>1001</
td
>
<
td
>java一班</
td
>
<
td
>30</
td
>
<
td
>2014-12-12</
td
>
<
td
>2015-12-12</
td
>
<
th
>
<
a
href
=
"classinfo_update.html"
>修改</
a
>
<
a
href
=
""
>删除</
a
>
</
th
>
</
tr
> <
tr
>
<
td
>1001</
td
>
<
td
>java一班</
td
>
<
td
>30</
td
>
<
td
>2014-12-12</
td
>
<
td
>2015-12-12</
td
>
<
th
>
<
a
href
=
"classinfo_update.html"
>修改</
a
>
<
a
href
=
""
>删除</
a
>
</
th
>
</
tr
> <
tr
>
<
td
>1001</
td
>
<
td
>java一班</
td
>
<
td
>30</
td
>
<
td
>2014-12-12</
td
>
<
td
>2015-12-12</
td
>
<
th
>
<
a
href
=
"classinfo_update.html"
>修改</
a
>
<
a
href
=
""
>删除</
a
>
</
th
>
</
tr
>
</
table
>
</
body
>
</
html
>
|
版权声明:原创作品,如需转载,请注明出处。否则将追究法律责任
本文转自 l363130002 51CTO博客,原文链接:http://blog.51cto.com/liuyj/1588468