日期:2014-05-18 浏览次数:20716 次
package com.test.action;
import java.io.InputStream;
import com.opensymphony.xwork2.ActionSupport;
public class DownloadAction extends ActionSupport {
public InputStream getTargetFile() throws Exception {
return new java.io.FileInputStream("F:\\222.doc");
}
public String execute() throws Exception {
return SUCCESS;
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<!--
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
-->
<constant name="struts.custom.i18n.resources" value="messages"/>
<constant name="struts.i18n.encoding" value="GBK"/>
<constant name="struts.objectFactory" value="spring"></constant>
<package name="struct2" namespace="/" extends="struts-default">
<action name="download" class="downloadAction" method="getTargetFile">
<result name="success" type="stream">
<!--<param name="contentType">application/excel</param>-->
<param name="contentType">text/plain</param>
<param name="inputName">targetFile</param>
<param name="contentDisposition">attachment;filename="222.txt"</param>
<param name="bufferSize">4096</param>
</result>
</action>
</package>
<!-- Add packages here -->
</struts>