---
title: "jsp 导出excel"
author: "fly-sky"
date: "2011-09-21T21:41:50Z"
tags: []
categories: ["编程语言"]
slug: "jsp-excel"
draft: false
lastmod: "2011-09-21T21:55:08Z"
id: 1177384
url: "https://fly-sky.iteye.com/blog/1177384"
---

excel文件是可以在jsp响应，通过输出相应xml，即可得到相应xls文件。 jsp相接导出excel文件实例： \[code="jsp"] &lt;%@ page language="java" contentType="text/html;charset=GBK"%&gt; &lt;%@ page import="java.util.\*" %&gt; &lt;%@ include file="/common/taglibs.jsp"%&gt; &lt;%@ page errorPage="../inc/error.jsp"%&gt; &lt;% response.setHeader("Content-Type", "application/vnd.ms-excel"); String fileName ="用户操作日志列表.xls"; fileName= new String(fileName.getBytes("GBK"),"ISO\_8859\_1"); response.addHeader("Content-Disposition", "attachment;filename=" + fileName); %&gt; 1996-12-17T01:32:42Z 2006-09-05T08:00:41Z 11.5606 4530 8505 480 120 False False 用户操作日志列表 序号 操作内容 操作用户 用户机构 用户Ip 访问时间 ${i} ${operateDescption.descption} ${operatename} ${operatelogid.department.name} ${ipaddress} ${operatetime}

9 300 300 3 2 5 False False False False

False False \[/code] 生成word格试： \[code="jsp"] &lt;%@ page contentType="application/vnd.ms-word; charset=utf-8"%&gt; &lt;%@ page pageEncoding="utf-8"%&gt; &lt;%@ page import="java.net.URLEncoder" %&gt; &lt;% String fileName = "test.doc"; //对中文文件名编码 fileName = URLEncoder.encode("test", "UTF-8") + ".doc"; response.setHeader("Content-disposition", "attachment; filename=" + fileName); %&gt; JSP页面导出为Word文档 。。。页面内容。。。 \[/code]