当项目部署到tomcat服务器时,JFrame中的Jasper预览不会打开

时间:2017-09-21 06:09:16

标签: java jasper-reports

所以我有一个小型的Web应用程序,可以从jasper报告中生成pdf文件。在通过eclipse运行时,jasper预览工作正常,但是当我将项目导出到war文件并将其部署到服务器时,jasper预览不再打开,尽管它仍然生成pdf文件。我一直在寻找在线解决方案,但我似乎找不到一个。

这是我的代码:

@SuppressWarnings({ "rawtypes", "unchecked" })
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    String outFileName = request.getParameter("directory") + "\\" + request.getParameter("reportName") + ".pdf";
    String fileName = request.getParameter("directory") + "\\" + request.getParameter("reportName") + ".jasper";
    String realPath = request.getSession().getServletContext().getRealPath("");
    Map<String, Object> parameters = new HashMap<String, Object>();

    if ("printJasper".equals(request.getParameter("action"))){
        try {
        parameters.put("P_ASSD_NO", request.getParameter("assdNo") == null ? "" : request.getParameter("assdNo"));  
        Connection conn = ConnectionUtil.getConnection();
        JasperPrint print = JasperFillManager.fillReport(fileName, parameters, conn);
        JasperFillManager.fillReportToFile(fileName, request.getParameter("directory") + "\\" + request.getParameter("reportName") + ".jrprint", parameters, conn);
        JRExporter exporter = new net.sf.jasperreports.engine.export.JRPdfExporter();
        exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, outFileName);
        exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
        exporter.exportReport();

        JFrame frame = new JFrame("Jasper report");
        JRViewer viewer = new JRViewer(print);

        frame.add(viewer);
        frame.setSize(new Dimension(500, 400));
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);

有谁能告诉我它为什么不起作用?

  

其他信息 - 使用:   Tomcat 8,Java 8

0 个答案:

没有答案