jsp:
pageEncoding="UTF-8"%>
Insert title herestruts.xml
text/plain
inputStream
attachment;filename="${downloadFileName}"
4096
com.hdsx.gzgispf.controller.FileDownloadAction :
/**
* 处理带中文的文件名(可设置下载文件名)
* @return
*/
public String getDownloadFileName() {
fileName="struts2的下载文件.doc";
String downloadFileName = null;
try {
downloadFileName = fileName;
downloadFileName = URLEncoder.encode(downloadFileName,"UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return downloadFileName;
}
/**
* 获取下载流
* @return
*/
public InputStream getInputStream () {
String context="";
String str="";
InputStream in=null;
//获取当前项目的路径 被下载的文件名为:111.doc
String path = ServletActionContext.getRequest().getSession().getServletContext().getRealPath("/")+"111.doc";
try {
File someFile = new File(path );
FileInputStream fis = new FileInputStream(someFile);
InputStreamReader isr = new InputStreamReader(fis,"UTF-8");
BufferedReader br = new BufferedReader(isr);
while((str=br.readLine())!=null){
context+=str+"\n";
}
in=new ByteArrayInputStream(context.getBytes());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return in ;
}
public String execute(){
return "success";
}