dilip Posted January 12, 2007 Share Posted January 12, 2007 Hi,This is dilip.I want to run simple webapplication using jasperreports.Iam using tomcat5.0,eclipse3.2.Iam using only two files.Those areHtmServlet.java[/ul]import java.lang.Object;import java.io.File;import java.io.IOException;import java.io.PrintWriter;import java.util.HashMap;import java.util.Map; import javax.servlet.ServletContext;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse; import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.JRExporterParameter;import net.sf.jasperreports.engine.JRRuntimeException;import net.sf.jasperreports.engine.JasperCompileManager;import net.sf.jasperreports.engine.JasperFillManager;import net.sf.jasperreports.engine.JasperPrint;import net.sf.jasperreports.engine.JasperReport;import net.sf.jasperreports.engine.export.JRHtmlExporter;import net.sf.jasperreports.engine.export.JRHtmlExporterParameter;import net.sf.jasperreports.engine.util.JRLoader;import net.sf.jasperreports.j2ee.servlets.ImageServlet;//import datasource.WebappDataSource;// public class Htmservlet extends HttpServlet{ public void service(HttpServletRequest request,HttpServletResponse response ) throws IOException, ServletException { ServletContext context = this.getServletConfig().getServletContext(); response.setContentType("text/html"); PrintWriter out = response.getWriter(); try {System.setProperty("jasper.reports.compile.class.path", context.getRealPath("/WEB-INF/lib/jasper.jar") + System.getProperty("path.separator") + context.getRealPath("/WEB-INF/classes/")); System.setProperty( "jasper.reports.compile.temp", context.getRealPath("/reports/")); JasperCompileManager.compileReportToFile( getServletContext().getRealPath( "/reports/sample.xml")); File reportFile = new File(getServletContext().getRealPath( "/reports/sample.jasper")); JasperReport jasperReport = (JasperReport) JRLoader.loadObject(reportFile.getPath()); Map parameters = new HashMap(); parameters.put("ReportTitle", "Address Report"); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,parameters); JRHtmlExporter exporter = new JRHtmlExporter(); request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out); exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "image?image="); exporter.exportReport(); } catch (JRException e) { out.println("<html>"); out.println("<head>"); out.println("<title>JasperReports - Web Application Sample</title>"); out.println("<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">"); out.println("</head>"); out.println("<body bgcolor="white">"); out.println("<span class="bnew">JasperReports encountered this error :</span>"); out.println("<pre>"); e.printStackTrace(out); out.println("</pre>"); out.println("</body>"); out.println("</html>"); } } }Sample.xml[/ul]<?xml version="1.0"?><!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd"><jasperReport name="sample"> <detail> <band height="20"> <staticText> <reportElement x="180" y="0" width="200" height="20"/> <text><![CDATA[Hello World!]]></text> </staticText> </band> </detail></jasperReport> Error showing was:JasperReports encountered this error : net.sf.jasperreports.engine.JRException: java.io.FileNotFoundException: C:Program FilesApache Software FoundationTomcat 5.0webappsssreportssample.xml (The system cannot find the path specified) at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:171) at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:151) at net.sf.jasperreports.engine.JasperCompileManager.compileReportToFile(JasperCompileManager.java:81) at Htmservlet.service(Htmservlet.java:50) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929) at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683) at java.lang.Thread.run(Thread.java:595)Caused by: java.io.FileNotFoundException: C:Program FilesApache Software FoundationTomcat 5.0webappsssreportssample.xml (The system cannot find the path specified) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.(FileInputStream.java:106) at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:166) ... 28 more Please Help me ..Its urgentThanks in advance Link to comment Share on other sites More sharing options...
manz_jasper Posted January 12, 2007 Share Posted January 12, 2007 ....net.sf.jasperreports.engine.JRException: java.io.FileNotFoundException: C:Program FilesApache Software FoundationTomcat 5.0webappsssreportssample.xml (The system cannot find the path specified)... That is right type or misspelled of name ? webappsssreportssample.xml ... Because the java can't find that file.put your all file in your folder. May it be help Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now