struts.xml配置: app
<action name="downloadDocument" class="mainAction" method="downloadDocument">
downloadDocument 方法 this
private InputStream is;
private String fileName; spa
public String downloadDocument(){
try{
String filePath = "\\a.doc";
String path=new String(filePath.getBytes("iso-8859-1"), "UTF-8");
String savePath = getRequest().getSession().getServletContext().getRealPath("/file");
File file = new File(savePath+path);
is = new FileInputStream(file);
fileName ="信息預算上報系統用戶操做手冊.doc";
fileName = new String(fileName.getBytes("gb2312"), "ISO8859-1");
}catch(Exception e){
e.printStackTrace();
}
return "downFile";
} xml
public InputStream getIs() {
return is;
} utf-8
public void setIs(InputStream is) {
this.is = is;
} get
public String getFileName() {
return fileName;
} input
public void setFileName(String fileName) {
this.fileName = fileName;
}
it