Struts download configuration information struts.xml
<Action name = "downloads" class = "com.lzw.web.action.DownloadAction" Method = "downloads">
<-! in the form of a stream file to the customer end of the reaction ->
<Result type = "Stream" >
<! - name of the input stream ->
<param name = "the inputName"> iNPUT </ param>
<param name = "contentDisposition"> Attachment; filename = $ {fileName} </ param>
<param name = "contentType "> file application / OCTET-Stream </ param>
</ Result>
</ Action>
Action
package com.lzw.web.action;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
com.opensymphony.xwork2.ActionSupport Import;
/ **
* written in Action in an input stream attribute
* provide get methods
* Write a download method to input assignment
* Add file write struts.xml Action
* @author the HP
*
* /
public the extends to DOWNLOADACTION ActionSupport {class
Private the InputStream INPUT;
Private String fileName;
public String getFileName () {
return fileName;
}
public getInput the InputStream () {
return INPUT;
}
public String downloads () throws a FileNotFoundException, UnsupportedEncodingException {
fileName = "a.jpg" ;
String path = "D: \\" + fileName;
the INPUT = new new FileInputStream (path);
// Chinese display
// fileName = "photos .jpg";
// fileName = URLEncoder.encode(fileName, "UTF-8");
return SUCCESS;
}
}