Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet Unable to call .jrxml file from jsp

Have Programming Question? Ask it here!
 
 
 


Ganesh D Ganbote
Unable to call .jrxml file from jsp
0 Answer(s)      3 years and 8 months ago
Posted in : JSP-Servlet


Hi, I am doing web application in jsp. To create report I have used ireport and interated with neatbeans using plugin. After creating report in netbean when i call that jrxml file then it unable to access it.Error also not showing. I will show my code and its output. Please refer to it and suggest what changes need to be done. The is as Follows: **In Report.jsp file*****

<%@page import="net.sf.jasperreports.engine.util.JRLoader"%> <%@page import="net.sf.jasperreports.view.JasperViewer"%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <%@page import="database.database_connection" %> <%@page import= "java.io.IOException;"%> <%@page import ="java.io.PrintWriter;"%> <%@page import ="java.io.StringWriter;"%> <%@page import= "java.util.HashMap;"%> <%@page import=" java.util.Map;"%> <%@page import=" java.sql.*;"%> <%@page import="database.CollectionDataSource"%> <%@page import=" javax.servlet.ServletException;"%> <%@page import=" javax.servlet.ServletOutputStream;"%> <%@page import=" javax.servlet.http.HttpServlet;"%> <%@page import=" javax.servlet.http.HttpServletRequest;"%> <%@page import=" javax.servlet.http.HttpServletResponse;"%> <%@page import=" net.sf.jasperreports.engine.*;"%> <%@page import=" net.sf.jasperreports.engine.design.JasperDesign;"%> <%@page import=" net.sf.jasperreports.engine.xml.JRXmlLoader;"%> <%@page import=" net.sf.jasperreports.engine.export.*;"%> <%@page import="database.database_connection" %>

<%@ page import="java.util.*" %> <%@ page import="java.sql.*" %> <%@ page import="java.io.*" %> <%@ page import="java.text.*" %> JSP Page

          <%
          ResultSet rsOfIncident = null;
       try {
                database_connection db1=new database_connection();
                if(db1.ConnectionStatus())
                 {

                      rsOfIncident =db1.getExecute("Select * from Incident");

                    }
                   db1.Close();
                 }
                catch(Exception e1)
                {
                }
    %>

             <%

Connection conn = null; JasperReport jasperReport; JasperPrint jasperPrint; JasperDesign jasperDesign; try { String connectionURL = "jdbc:mysql://localhost:3306/ticketingtool"; Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager.getConnection(connectionURL,"root",""); JRDataSource dataSource = new JRResultSetDataSource(rsOfIncident);

// create a map of parameters to pass to the report. Map parameters = new HashMap(); parameters.put("IncidentID", "FirstName"); jasperDesign = JRXmlLoader.load("E:/GRS/6th BacUp/ticketingtool/web/report2.jrxml"); jasperReport = JasperCompileManager.compileReport(jasperDesign);

// fill JasperPrint using fillReport() method jasperPrint = JasperFillManager.fillReport(jasperReport,parameters,dataSource);

JasperExportManager.exportReportToPdfFile(jasperPrint,"C:/demo.pdf"); response.setContentType("report2.jrxml"); JasperViewer.viewReport(jasperPrint); } catch(SQLException sqle) { System.err.println(sqle.getMessage()); } catch (ClassNotFoundException e) { System.err.println("No such class found!"); } catch (JRException e) { // display stack trace in the browser StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); e.printStackTrace(printWriter); response.setContentType("text/plain"); } finally { //close the connection. if(conn != null) { try { conn.close(); } catch (Exception ignored) {} } } %>

             <table>
                 <tr>
                     <td>
                         Hello
                     </td>
                 </tr>
             </table>
   </form>
</body>

***And it output**** Here output display in browser.

JSP Page

             <table>
                 <tr>
                     <td>
                         Helo
                     </td>
                 </tr>
             </table>
   </form>
</body>


Advertisement
View Answers

Related Tutorials/Questions & Answers:
 

 

 

DMCA.com