JSP 导出EXCEL文件

把JSP里面的contentType设置为:

contentType="application/vnd.ms-excel; charset=UTF-8"


打开页面的时候就可以直接保存为一个EXCEL文件


代码示例


<%@ 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>


你可能感兴趣的:(jsp,Excel)