日期:2014-05-16 浏览次数:20452 次
PrintWriter out = response.getWriter(); out.println("xxxx\t"); out.flush(); out.close();
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd"> <struts-config> <form-beans /> <global-exceptions /> <global-forwards /> <action-mappings > <action path="/exportExcel" type="com.mypack.struts.action.ExportExcelAction" cancellable="true"> <forward name="downloadPage" path="/jsp/downloadPage.jsp" /> </action> </action-mappings> <message-resources parameter="com.mypack.struts.ApplicationResources" /> </struts-config>
/* * Generated by MyEclipse Struts * Template path: templates/java/JavaClass.vtl */ package com.mypack.struts.action; import java.util.ArrayList; import java.util.List; import java.util.UUID; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; /** * MyEclipse Struts * Creation date: 11-07-2010 * * XDoclet definition: * @struts.action validate="true" */ public class ExportExcelAction extends Action { @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { List list = new ArrayList(); for (int i = 0; i < 100; i ++) { list.add(UUID.randomUUID().toString()); } request.setAttribute("result", list); System.out.println(list); response.setContentType("application/vnd.ms-excel;charset=UTF-8"); //response.setHeader("Content-Disposition" ,"attachment;filename=report"); response.setHeader ("Content-Disposition","attachment;filename="+ UUID.randomUUID() +".xls"); return mapping.findForward("downloadPage"); } }
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"> <head> <meta http-equiv=Content-Type content="text/html; charset=gb2312"> <meta name=ProgId content=Excel.Sheet> <meta name=Generator content="Microsoft Excel 11"> <link rel=File-List href="Book2.files/filelist.xml"> <link rel=Edit-Time-Data href="Book2.files/editdata.mso"> <link rel=OLE-Object-Data href="Book2.files/oledata.mso"> <!--[if gte mso 9]><xml> <o:DocumentProperties> <o:Author>微软用户</o:Author> <o:LastAuthor>微软用户</o:LastAuthor> <o:Created>2010-11-07T08:34:34Z</o:Created> <o:LastSaved>2010-11-07T08:38:14Z</o:LastSaved> <o:Company>微软中国</o:Company> <o:Version>11.9999</o:Version> </o:DocumentProperties> </xml><![endif]--> <style> <!--table {mso-displayed-decimal-separator:"\."; mso-displayed-thousand-separator:"\,";} @page {margin:1.0in .