锘??xml version="1.0" encoding="utf-8" standalone="yes"?>欧美www.,亚洲超碰精品一区二区,亚洲第一se情网站http://www.aygfsteel.com/HappyJava/category/34720.html騫哥浜虹敓(J2EE)zh-cnFri, 19 Sep 2008 12:06:31 GMTFri, 19 Sep 2008 12:06:31 GMT60Struts2鍒╃敤stream鐩存帴杈撳嚭Excelhttp://www.aygfsteel.com/HappyJava/articles/229873.html鏉庡緩杌?/dc:creator>鏉庡緩杌?/author>Fri, 19 Sep 2008 01:57:00 GMThttp://www.aygfsteel.com/HappyJava/articles/229873.htmlhttp://www.aygfsteel.com/HappyJava/comments/229873.htmlhttp://www.aygfsteel.com/HappyJava/articles/229873.html#Feedback0http://www.aygfsteel.com/HappyJava/comments/commentRss/229873.htmlhttp://www.aygfsteel.com/HappyJava/services/trackbacks/229873.html 涓銆乻truts.xml
<? xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
  
<struts>

    <constant name="struts.i18n.encoding" value="UTF-8"/>

    <package name="demo" extends="struts-default">
        <action name="excel" method="execute" class="demo.ExcelAction">
                <result name="excel" type="stream">
                    <param name="contentType">application/vnd.ms-excel</param>    <!-- 娉ㄦ剰榪欓噷鐨凜ontentType -->
                    <param name="inputName">excelStream</param>                   <!-- 榪欓噷闇瑕佸拰Action閲岀殑鍙橀噺鍚嶄竴鑷?-->
                    <param name="contentDisposition">filename="standard.xls"</param>
                    <param name="bufferSize">1024</param>
                </result>
        </action>
    </package>
</struts>

浜屻丼truts2鐨?Action

package demo;
public class ExcelAction {
    private InputStream excelStream; // 闇瑕佺敓鎴恎etter鍜宻etter

    public String execute() throws Exception {
        StringBuffer excelBuf = new StringBuffer();
        excelBuf.append("BookName").append("\t").append("Year").append("\t").append("author").append("\n");
        excelBuf.append("Thinking in Java").append("\t").append("2001").append("\t").append("Eckel").append("\n");
        excelBuf.append("Spring in action").append("\t").append("2005").append("\t").append("Rod").append("\n");
        String excelString = excelBuf.toString();
        logger.debug("result excel String: " + excelString);
        excelStream = new ByteArrayInputStream(excelString.getBytes(), 0, excelString.length());
        return "excel";
    }

    // getter and setter
    ...
}

涓夈丣sp欏甸潰

<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <s:head />
 </head>

 <body>

    <s:form action="" method="post">
       <s:submit key="button.submit"/>
    </s:form>
 </body>
</html>



]]>
主站蜘蛛池模板: 翁牛特旗| 和政县| 东光县| 淮北市| 营口市| 科尔| 诸城市| 乳源| 辽阳市| 扶沟县| 彩票| 寻乌县| 项城市| 洪湖市| 炉霍县| 吉首市| 股票| 德钦县| 蓝山县| 红原县| 湘潭县| 许昌市| 龙游县| 左云县| 额敏县| 汉中市| 宣城市| 河间市| 广东省| 岢岚县| 桃源县| 沙河市| 大田县| 绵阳市| 应用必备| 翁牛特旗| 上栗县| 博爱县| 永州市| 崇阳县| 吉首市|