加了struts2-sunspoter-stream-1.0.jar
在struts.xml中进行配置
<result-types>  
<result-type name="streamx" class="com.sunspoter.lib.web.struts2.dispatcher.StreamResultX"/>  
</result-types>
<result name="success" type="streamx"> …… </result>
结果 报java.lang.NoSuchMethodError: com.sunspoter.lib.web.struts2.dispatcher.StreamResultX.resolveParamsFromStack(Lcom/opensymphony/xwork2/util/ValueStack;Lcom/opensymphony/xwork2/ActionInvocation;)V
StreamResultX类继承自org.apache.struts2.dispatcher.StreamResult,这里怎么会找不到resolveParamsFromStack,求指导!!!Struts异常

解决方案 »

  1.   

    java.lang.NoSuchMethodError
    这个异常很多是包版本不对造成的
      

  2.   

    下载就是一个response的事情,往客户端输出流就可以了,没必要整的这么复杂把struts也扯进来,根本就不需要配置:
    /**
     * 下载
     * @param filePath 文件路径(物理路径)
     * @param fileName 输出的文件名
     */
    public static void downLoad(String filePath, String fileName) {
    downLoad(new File(filePath), fileName);
    }

    /**
     * 下载
     * @param file 文件
     * @param fileName 输出的文件名
     */
    public static void downLoad(File file, String fileName) {
    try {
    if (file.exists() && file.isFile()) {
    downLoad(new FileInputStream(file), fileName);
    }
    } catch (Exception e) {
    log.error("下载", e);
    }
    }

    /**
     * 下载
     * @param input 输入流
     * @param fileName 输出的文件名
     */
    public static void downLoad(InputStream input, String fileName) {
    OutputStream output = null;
    try {
    HttpServletResponse response = ResponseThreadLocal.get();
    output = response.getOutputStream();
    response.setHeader("Content-disposition", "attachment;filename=" + new String(fileName.getBytes("GBK"), CharEncoding.ISO_8859_1));
    byte[] buffer = new byte[1024];
    int i = 0;
    while ((i = input.read(buffer)) != -1) {
    output.write(buffer, 0, i);
    }
    } catch (Exception e) {} finally {
    try {
    if(null !=output) {
    output.flush();
    output.close();
    }
    if(null !=input) {
    input.close();
    }
    } catch (Exception e) {}
    }
    }
    根据具体情况,选一个方法试试吧
      

  3.   

    以上代码是兼容任何浏览器(包括IE5.5),任何操作系统的,
    HttpServletResponse response = ResponseThreadLocal.get();
    这行代码,你可能用不来,我们项目里把request和response放在线程池里了,
    如果你整不来,把它们当参数传进来就可以了