jsp
<s:form action="downLoad" method="post">
<s:file name="fileName"/>
<s:submit value="下载"/>
</s:form>
struts.xml
<action name="downLoad" class="an.action.DownLoadLoginAction" method="downLoad">
<result type="stream">
<param name="contentType">image/jpeg</param>
<param name="contentDisposition">attachment;filename=${fileName}</param>
</result>
</action>
downLoadAction
package an.action;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import com.opensymphony.xwork2.ActionSupport;
public class DownLoadLoginAction extends ActionSupport {
private InputStream inputStream;
private String fileName;
//编写方法
public String downLoad() throws FileNotFoundException{
System.out.println(fileName);
inputStream= new FileInputStream("E:\"+fileName);
return SUCCESS;
}
public InputStream getInputStream() {
return inputStream;
}
public void setInputStream(InputStream inputStream) {
this.inputStream = inputStream;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
}