struts.xml文件配置:↓





    
      
      
      
      
      
      
        
        
                                 
           
           
          
             ${resType}
             
             inp
             
             fileName=${resName}
                                       
           
        
                                
        
         /WEB-INF/view/{1}.jsp
        
      
    


DownloadAction.java↓


package com.ssh4.download;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
@SuppressWarnings("serial")
public class DownloadAction extends ActionSupport {
  private String res;    //资源文件,
  private String resName;  //自定义被下载的文件名;
  private String resType;  //文件类型
public String getRes() {
    return res;
}
public void setRes(String res) throws UnsupportedEncodingException {
      //处理中文资源文件
        this.res = new String(res.getBytes("iso-8859-1"),"utf-8");
}
public String getResName() {
    return resName;
}
public void setResName(String resName) {
    this.resName = resName;
}
public String getResType() {
    return resType;
}
public void setResType(String resType) {
    this.resType = resType;
}
//下载文件必须有此方法
public InputStream getInp() throws FileNotFoundException{
    //资源文件的路径
    String path = ServletActionContext.getServletContext().getRealPath("/") +"WEB-INF\\download\\"+ res;
    System.out.println(path);
    return new FileInputStream(path);
                 
 }
}