Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Exception in Jasper Report while integrating of Jasper report with Struts

Posted on 2009-05-15
5
Medium Priority
?
897 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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.
Suggested Courses

636 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