Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 让JasperReports生成的pdf显示在使用Struts2 framework的浏览器上_Java_Pdf_Struts2_Jasper Reports - Fatal编程技术网

Java 让JasperReports生成的pdf显示在使用Struts2 framework的浏览器上

Java 让JasperReports生成的pdf显示在使用Struts2 framework的浏览器上,java,pdf,struts2,jasper-reports,Java,Pdf,Struts2,Jasper Reports,我正在使用Jasper Reports框架和我的Struts2 web应用程序。直到不久前,我才意识到JasperViewer不能帮助我在客户端浏览器中显示和下载我的报告。我看到了一些链接,几乎所有的链接都告诉我使用servlet和OutputStreams来实现这一点。我对这一点非常新,所以使用这些源代码等的各种尝试都不起作用。这就是为什么我张贴此帮助 我的Action类方法的相关代码是 public String execute() throws Exception //the method

我正在使用Jasper Reports框架和我的Struts2 web应用程序。直到不久前,我才意识到JasperViewer不能帮助我在客户端浏览器中显示和下载我的报告。我看到了一些链接,几乎所有的链接都告诉我使用servlet和OutputStreams来实现这一点。我对这一点非常新,所以使用这些源代码等的各种尝试都不起作用。这就是为什么我张贴此帮助

我的Action类方法的相关代码是

public String execute() throws Exception //the method which will be executed
{
                ...
                request=ServletActionContext.getRequest();
                response = ServletActionContext.getResponse();
                if(response!=null)
                    System.out.println("Response is not null");
                System.out.println("coming to this method");
                java.io.InputStream in = this.getClass().getClassLoader().getResourceAsStream("com/ram/report/jasper/Report.jrxml");
                JasperReport jasperReport=JasperCompileManager.compileReport(in);
                HashMap<String, Object> params = new HashMap<String, Object>();             
                JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params,new JRBeanCollectionDataSource(list));
                JRPdfExporter pdfExporter = new JRPdfExporter();
                List<JasperPrint> jasperPrintList= new ArrayList<JasperPrint>(); 
                jasperPrintList.add(jasperPrint);
                pdfExporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST,jasperPrintList);
                pdfExporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME ,request.getRealPath("")+"/Report.pdf");
                pdfExporter.exportReport();

            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
            return "ajaxReturn";
        }
        }
            return "success";
    }   
publicstringexecute()引发异常//将要执行的方法
{
...
request=ServletActionContext.getRequest();
response=ServletActionContext.getResponse();
if(响应!=null)
System.out.println(“响应不为空”);
System.out.println(“使用此方法”);
java.io.InputStream in=this.getClass().getClassLoader().getResourceAsStream(“com/ram/report/jasper/report.jrxml”);
JasperReport-JasperReport=JasperCompileManager.compileReport(in);
HashMap params=新的HashMap();
JasperPrint JasperPrint=JasperFillManager.fillReport(jasperReport,params,新的JRBeanCollectionDataSource(list));
JRPdfExporter PDFEEXPORTER=新的JRPdfExporter();
List jasperPrintList=newarraylist();
jasperPrintList.add(jasperPrint);
pdfExporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST,JASPER PRINT LIST);
pdfExporter.setParameter(jreporterParameter.OUTPUT_文件名,request.getRealPath(“”+“/Report.pdf”);
pdfExporter.exportReport();
}
捕获(例外e)
{
e、 printStackTrace();
}
返回“ajaxReturn”;
}
}
返回“成功”;
}   
我的操作(struts.xml从中链接到)


htdocs/jsp/report\u new/report\u tool.jsp
申请表格/pdf
在里面
1024
我得到了这个错误

Exception occurred during processing request: Can not find a java.io.InputStream with the name [inputStream] in the invocation stack. Check the <param name="inputName"> tag specified for this action.
java.lang.IllegalArgumentException: Can not find a java.io.InputStream with the name [inputStream] in the invocation stack. Check the <param name="inputName"> tag specified for this action.
处理请求期间发生异常:在调用堆栈中找不到名为[InputStream]的java.io.InputStream。检查为此操作指定的标记。 java.lang.IllegalArgumentException:在调用堆栈中找不到名为[InputStream]的java.io.InputStream。检查为此操作指定的标记。 问题是在此之前,当我使用JasperViewer查看我的Jasper文件时,它工作得很好。
我应该如何解决此错误并下载我的pdf

使用搜索->如何在S2中下载文件。或者甚至->如何在S2中使用jasper报表。@AleksandrM我设法消除了错误,并使用outputStream来完成。将删除此问题。@AleksandrM我发布了一个稍微不同的问题。你们能查一下吗?使用搜索->如何在S2下载文件。或者甚至->如何在S2中使用jasper报表。@AleksandrM我设法消除了错误,并使用outputStream来完成。将删除此问题。@AleksandrM我发布了一个稍微不同的问题。你能调查一下吗?
Exception occurred during processing request: Can not find a java.io.InputStream with the name [inputStream] in the invocation stack. Check the <param name="inputName"> tag specified for this action.
java.lang.IllegalArgumentException: Can not find a java.io.InputStream with the name [inputStream] in the invocation stack. Check the <param name="inputName"> tag specified for this action.