文件下载之java.io.FileInputStream cannot be cast to java.lang.String

java.io.FileInputStream cannot be cast to java.lang.String

难者不会,会者不难

struts.xml   注意,method没有了,换为了下面的inputName

<action name="fileDownload" class="demand">  
            <result type="stream" name="success">  
                <param name="contentDisposition">attachment;filename=${filename}</param>  
                <!--action的方法名,需多添加“get”方法名为:getInputStream()-->
                <param name="inputName">downloadFile</param>
            </result>  
</action> 

public InputStream getDownloadFile() throws Exception{
System.out.println("filepath:"+filepath);
System.out.println("filename:"+filename);
String filePath = "/WEB-INF/upload" + File.separator + filepath;
InputStream in=ServletActionContext.getServletContext().getResourceAsStream(filePath);
System.out.println(in);
return ServletActionContext.getServletContext().getResourceAsStream(
filePath);
}


 
 
参考:struts2下载已存在excel文件报java.lang.ClassCastException: java.io.FileInputStream cannot be cast

你可能感兴趣的:(文件下载之java.io.FileInputStream cannot be cast to java.lang.String)