getOutputStream() has already been called for this response java.lang.IllegalStateException: getOutp

来源:互联网 发布:淘宝客服培训ppt下载 编辑:程序博客网 时间:2024/05/22 12:18

今天在做一个用openOffice插件把office文档转换成为PDF格式,并在线预览的时候,报了这个错误,看到了一个网友的分享突然明白,原来是在线预览的方法是用流的形式输

出到前台的,然后这个方法竟然写了返回值为String。

    public String  transferToPDf() throws Exception{
        dataMap  = new HashMap<String,Object>();
        String tempName = UUIDGenerator.getUUID() + ".pdf";
        try {
            ConvertToPDFUtils.converterFile(FilePath.FULL_UPLOAD_PATH + File.separator + saveName, FilePath.TEMP_PATH + File.separator + tempName);
            readDocs(tempName,FilePath.TEMP_PATH);
        } catch (Exception e) {
            log.error("office转换失败:"+e);
        }finally{
            FileUtils.deleteFile(FilePath.TEMP_PATH + File.separator + tempName);
        }
    }

因为struts中,每个action方法都返回一个actionForword对象,而response是actionforword对象参数,所以就会使得response冲突,然后把action的方法返回为null就行了。

这里值得注意的是,在线读取文件一定用的是流的形式来读取的,不用返回值。

阅读全文
0 0