Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

opening a pdf file created by jasper in client side

 
jothish chokkalingam
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I m using jasper reports to my project...
here is my servlet class i m using ..
i want to get the output from of the pdf file in client side...
but i m not getting the stream of pdf in client side...
even there is no errror showing in the tomcat server when i load nthis servlet using an html file ......
help is needed urgently

/* Program or JASPER Engine to convert the .JRXML file to a report and the exporting it to .PDF file */
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrintManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.engine.JRException;
import java.io.*;
import java.net.*;
import java.sql.*;
import java.util.*;
import java.sql.*;
import java.io.File;
import java.util.Date;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.view.JasperViewer;
import net.sf.jasperreports.engine.JasperPrintManager;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletOutputStream;
import java.io.PrintWriter;
import java.io.IOException;
public class SimpleServlet extends HttpServlet{

public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException{


try{
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
Class.forName ("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection("jdbc racle:thin:@10.236.8.49:1521:heb","hebuser","hebpass");
// @machineName ort:SID, userid, password
// int i=0,j=0;
String query = "select * from storeevent1";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query);


System.out.println("The context path is >>>>>>>>>> " + request.getContextPath());
/
String src= "/heb.jrxml";
net.sf.jasperreports.engine.design.JasperDesign jDesign = net.sf.jasperreports.engine.xml.JRXmlLoader.load(src);
JasperReport jReport = net.sf.jasperreports.engine.JasperCompileManager.compileReport(jDesign);

Map p1 = new HashMap();

JasperPrint jPrint= JasperFillManager.fillReport( jReport,null,conn );

OutputStream out = response.getOutputStream();
net.sf.jasperreports.engine.JasperExportManager.exportReportToPdfStream(jPrint,out);
System.out.println(jPrint);
System.out.println(out);
System.out.println("next");
rs.close();
stmt.close();
conn.close();
}
catch(Exception e)
{
e.printStackTrace();
}

}
}

help me regarding this
--------------------

jothi
[ January 11, 2006: Message edited by: Bear Bibeault ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you seeing any error messages in the Tomcat logs?
 
jothish chokkalingam
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The log file of my server.....
I couldn't find any error in this log...

2006-01-05 18:44:14 HostConfig[localhost]: Deploying configuration descriptor admin.xml
2006-01-05 18:44:15 HostConfig[localhost]: Deploying configuration descriptor manager.xml
2006-01-05 18:44:15 WebappLoader[/manager]: Deploying class repositories to work directory C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\manager
2006-01-05 18:44:15 ContextConfig[/manager]: Configured an authenticator for method BASIC
2006-01-05 18:44:15 StandardManager[/manager]: Seeding random number generator class java.security.SecureRandom
2006-01-05 18:44:15 StandardManager[/manager]: Seeding of random number generator has been completed
2006-01-05 18:44:15 StandardWrapper[/manager efault]: Loading container servlet default
2006-01-05 18:44:15 StandardWrapper[/manager:invoker]: Loading container servlet invoker
2006-01-05 18:44:15 HostConfig[localhost]: Deploying web application directory ROOT
2006-01-05 18:44:15 StandardHost[localhost]: Installing web application at context path from URL file:C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT
2006-01-05 18:44:15 WebappLoader[]: Deploying class repositories to work directory C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\_
2006-01-05 18:44:15 WebappLoader[]: Deploy class files /WEB-INF/classes to C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\classes
2006-01-05 18:44:15 WebappLoader[]: Deploy JAR /WEB-INF/lib/ant-1.5.1.jar to C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\lib\ant-1.5.1.jar
2006-01-05 18:44:15 WebappLoader[]: Deploy JAR /WEB-INF/lib/classes12.jar to C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\lib\classes12.jar
2006-01-05 18:44:16 WebappLoader[]: Deploy JAR /WEB-INF/lib/commons-beanutils-1.5.jar to C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\lib\commons-beanutils-1.5.jar
2006-01-05 18:44:16 WebappLoader[]: Deploy JAR /WEB-INF/lib/commons-collections-2.1.jar to C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\lib\commons-collections-2.1.jar
2006-01-05 18:44:16 WebappLoader[]: Deploy JAR /WEB-INF/lib/commons-digester-1.7.jar to C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\lib\commons-digester-1.7.jar
2006-01-05 18:44:16 WebappLoader[]: Deploy JAR /WEB-INF/lib/commons-logging-1.0.2.jar to C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\lib\commons-logging-1.0.2.jar
2006-01-05 18:44:16 WebappLoader[]: Deploy JAR /WEB-INF/lib/commons-logging-api-1.0.2.jar to C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\lib\commons-logging-api-1.0.2.jar
2006-01-05 18:44:16 WebappLoader[]: Deploy JAR /WEB-INF/lib/hsqldb-1.61.jar to C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\lib\hsqldb-1.61.jar
2006-01-05 18:44:16 WebappLoader[]: Deploy JAR /WEB-INF/lib/itext-1.3.1.jar to C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\lib\itext-1.3.1.jar
2006-01-05 18:44:16 WebappLoader[]: Deploy JAR /WEB-INF/lib/jasperreports-1.1.1.jar to C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\lib\jasperreports-1.1.1.jar
2006-01-05 18:44:16 WebappLoader[]: Deploy JAR /WEB-INF/lib/jcommon-1.0.0-rc1.jar to C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\lib\jcommon-1.0.0-rc1.jar
2006-01-05 18:44:16 WebappLoader[]: Deploy JAR /WEB-INF/lib/jdt-compiler-3.1.1.jar to C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\lib\jdt-compiler-3.1.1.jar
2006-01-05 18:44:16 WebappLoader[]: Deploy JAR /WEB-INF/lib/jfreechart-1.0.0-rc1.jar to C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\lib\jfreechart-1.0.0-rc1.jar
2006-01-05 18:44:16 WebappLoader[]: Deploy JAR /WEB-INF/lib/poi-2.0-final-20040126.jar to C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\lib\poi-2.0-final-20040126.jar
2006-01-05 18:44:16 WebappLoader[]: Deploy JAR /WEB-INF/lib/servlet.jar to C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\lib\servlet.jar
2006-01-05 18:44:16 WebappLoader[]: Deploy JAR /WEB-INF/lib/xalan.jar to C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\lib\xalan.jar
2006-01-05 18:44:16 WebappLoader[]: Deploy JAR /WEB-INF/lib/xercesImpl.jar to C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\lib\xercesImpl.jar
2006-01-05 18:44:16 WebappLoader[]: Deploy JAR /WEB-INF/lib/xml-apis.jar to C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\WEB-INF\lib\xml-apis.jar
2006-01-05 18:44:16 StandardManager[]: Seeding random number generator class java.security.SecureRandom
2006-01-05 18:44:16 StandardManager[]: Seeding of random number generator has been completed
2006-01-05 18:44:16 StandardWrapper[ efault]: Loading container servlet default
2006-01-05 18:44:16 StandardWrapper[:invoker]: Loading container servlet invoker
2006-01-05 18:44:16 HostConfig[localhost]: Deploying web application directory tomcat-docs
2006-01-05 18:44:16 StandardHost[localhost]: Installing web application at context path /tomcat-docs from URL file:C:\Program Files\Apache Group\Tomcat 4.1\webapps\tomcat-docs
2006-01-05 18:44:17 WebappLoader[/tomcat-docs]: Deploying class repositories to work directory C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\tomcat-docs
2006-01-05 18:44:17 StandardManager[/tomcat-docs]: Seeding random number generator class java.security.SecureRandom
2006-01-05 18:44:17 StandardManager[/tomcat-docs]: Seeding of random number generator has been completed
2006-01-05 18:44:17 StandardWrapper[/tomcat-docs efault]: Loading container servlet default
2006-01-05 18:44:17 StandardWrapper[/tomcat-docs:invoker]: Loading container servlet invoker
2006-01-05 18:44:17 HostConfig[localhost]: Deploying web application directory webdav
2006-01-05 18:44:17 StandardHost[localhost]: Installing web application at context path /webdav from URL file:C:\Program Files\Apache Group\Tomcat 4.1\webapps\webdav
2006-01-05 18:44:17 WebappLoader[/webdav]: Deploying class repositories to work directory C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\webdav
2006-01-05 18:44:17 StandardManager[/webdav]: Seeding random number generator class java.security.SecureRandom
2006-01-05 18:44:17 StandardManager[/webdav]: Seeding of random number generator has been completed
2006-01-05 18:44:17 StandardWrapper[/webdav efault]: Loading container servlet default
2006-01-05 18:44:17 StandardWrapper[/webdav:invoker]: Loading container servlet invoker

help urgently needed
[ January 05, 2006: Message edited by: jothi chokalingam ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by jothi chokalingam:
help urgently needed

[ January 05, 2006: Message edited by: jothi chokalingam ]


Please read this.
 
jothish chokkalingam
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello guys
i resolved the problem my servlet code is
/* Program or JASPER Engine to convert the .JRXML file to a report and the exporting it to .PDF file */
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrintManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.engine.JRException;
import java.io.*;
import java.net.*;
import java.sql.*;
import java.util.*;
import java.sql.*;
import java.io.File;
import java.util.Date;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.view.JasperViewer;
import net.sf.jasperreports.engine.JasperPrintManager;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletOutputStream;
import java.io.PrintWriter;
import java.io.IOException;
public class SimpleServlet extends HttpServlet{

public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException{


try{
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
Class.forName ("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection("jdbc racle:thin:@10.236.8.49:1521:heb","hebuser","hebpass");
// @machineName ort:SID, userid, passw//int i=0,j=0String query = "select * from storeevent1" Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(query);


System.out.println("The context path is >>>>>>>>>> " + request.getContextPath());

String src= "/heb.jrxml";
net.sf.jasperreports.engine.design.JasperDesign jDesign = net.sf.jasperreports.engine.xml.JRXmlLoader.load(src);
JasperReport jReport = net.sf.jasperreports.engine.JasperCompileManager.compileReport(jDesign);

Map p1 = new HashMap();

ByteArrayOutputStream baos =new ByteArrayOutputStream();
response.setContentType("application/pdf");
JasperPrint jPrint= JasperFillManager.fillReport( jReport,null,conn );

net.sf.jasperreports.engine.JasperExportManager.exportReportToPdfStream(jPrint,baos);
response.setContentLength(baos.size());
ServletOutputStream out1 = response.getOutputStream();
baos.writeTo(out1);
out1.flush();

rs.close();
stmt.close();
conn.close();
}
catch(Exception e)
{
e.printStackTrace();
}

}
}

tom cat server 4.1
jasper reports version is 1.1.1
jdk version 1.4.2
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
jothish chokkalingam
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no problem ben
i have resolved it....
thanks
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My point was that many people will search these forum to find answers to similar problems. When doing so, it's frustrating to find that someone else had the same problem and solved it but didn't note the solution.

What did you do that fixed it?
 
jothish chokkalingam
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
create a bytearrayoutputstream object
/*ByteArrayOutputStream baos =new ByteArrayOutputStream();*/
set the content type for the response as pdf
/*response.setContentType("application/pdf");*/
fill the outputstream object baos with jPrint object
/*net.sf.jasperreports.engine.JasperExportManager.exportReportToPdfStream(jPrint,baos);*/
set the content size for the output file (pdf)
/*response.setContentLength(baos.size());*/
instantiate an object as ServletOutputStream to view the file in webpage
/*ServletOutputStream out1 = response.getOutputStream();*/
write the exported outputstream to the servlet outputstream
/*baos.writeTo(out1);*/
file nameis:SimpleServlet.java
one more thing ben i have createda new topic
creating xls file using jasper report....
could you please answer for me in this thread......
http://www.coderanch.com/forums/f-64/open-source
[ January 11, 2006: Message edited by: jothish chokkalingam ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic