import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class FileDown extends ActionSupport{
/**
*
*/
private static final long serialVersionUID = 1L;
private String filename;
public String getFilename() throws UnsupportedEncodingException {
return new String(filename.getBytes(), "iso8859-1");
}
public void setFilename(String filename) {
this.filename = filename;
}
public InputStream getInputStream() throws Exception {
filename="java.xlsx";
return ServletActionContext.getServletContext().getResourceAsStream("/upload/"+filename);
}
}
struts.xml
<action name="filedownload" class="com.java111.FileDown">
<result name="success" type="stream">
<param name="contentDisposition">attachment;filename=${filename }</param>
<param name="location">main.jsp</param>
</result>
</action