?
Solved

Exception in Jasper Report while integrating of Jasper report with Struts

Posted on 2009-05-15
5
Medium Priority
?
896 Views
Last Modified: 2013-11-24
I m getting the null value in         InputStream reportStream = getServlet().getServletConfig().getServletContext().getResourceAsStream("/reports/DbReport.jasper");
 While i integrate the jasper report with struts framework.

i have already the compile file with DbReport.jasper in report folder
i m attaching the DbReport.jasper file also..

please tell me why this exception and null value come

package net.ensode.jasperbook.struts;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.HashMap;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperRunManager;
 
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class GenerateReportAction extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
    Connection connection=null;
    ServletOutputStream servletOutputStream =response.getOutputStream();
 
    InputStream reportStream = getServlet().getServletConfig().getServletContext().getResourceAsStream("/reports/DbReport.jasper");
    
 
    System.out.println("ReportStream---------->>>>>>>>>>>>>>>>"+reportStream);
    response.setContentType("application/pdf");
 
     try{
           Class.forName("com.mysql.jdbc.Driver").newInstance();
           connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/ashu_db","root","mysql");
           System.out.println("After load Driver========================");
      
           JasperRunManager.runReportToPdfStream(reportStream,servletOutputStream, new HashMap(), connection);
        }catch(Exception e){
            e.printStackTrace();
        }
    finally{
      connection.close();
      servletOutputStream.flush();
      servletOutputStream.close();
    }
    return mapping.getInputForward();
    }
}

Open in new window

0
Comment
Question by:Adwait Chitaley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 12

Expert Comment

by:Gibu George
ID: 24394805
InputStream reportStream = getServlet().getServletConfig().getServletContext().getResourceAsStream(<request.getContextPath()+"/reports/DbReport.jasper");
0
 
LVL 12

Expert Comment

by:Gibu George
ID: 24394811
remove the < sign is a typo

InputStream reportStream = getServlet().getServletConfig().getServletContext().getResourceAsStream(request.getContextPath()+"/reports/DbReport.jasper");
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 1500 total points
ID: 24395091
Try
InputStream reportStream = new FileInputStream(request.getRealPath("/reports/DbReport.jasper"));

Open in new window

0
 
LVL 92

Expert Comment

by:objects
ID: 24400402
make sure your reports directory is inside your classes directory

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24571418
:-)
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month13 days, 15 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question