Jump to content
We've recently updated our Privacy Statement, available here ×

Help with passing parameters from java


2004 IR Help

Recommended Posts

By: Marc - kantspel

Help with passing parameters from java

2004-08-16 19:01

Hello.

 

I searched the forums and couldn't find anything that totally explained the way to pass a parameter from java to your compiled report.

The report I have I designed in iReport, and it works with the default parameter.

Now I would like to pass in this parameter, but I've read through the totally confusing documentation about JasperReports, and I have absolutely no idea how to do it.

I would like to, if possible, pass in a dynamic parameter in the URL, but it doesn't have to if not need be.

I'm kind of a beginner, so if anyone could point me in the right direction, that would be great.

 

Thank you

Marc

 

 

 

 

By: flying - ibmj2ee

RE: Help with passing parameters from java

2004-08-16 20:28

please particular desribe your question?

 

 

 

 

 

By: C-Box - c-box

RE: Help with passing parameters from java

2004-08-16 21:32

Hi,

 

try lilke this:

 

String fileNameOfMyReportAsJasper = new String("C:/myreport.jasper");

JasperReport myRep = (JasperReport) JRLoader.loadObject(fileNameOfMyReportAsJasper);

Map parameters = new HashMap();

parameters.put("YourParamName1", param1);// param1 could be EVERYTHING you like

parameters.put("YourParamName2", param2);// param2 could be EVERYTHING you like

parameters.put("YourParamName3", param3);// param3 could be EVERYTHING you like

JasperPrint jasperPrint = JasperFillManager.fillReport(myRep, parameters, yourGetMethodForConnectionRetrieval()); // you can pass also a JRDataSource or a direct connection that you get befor the fillroutine.

 

You have to set the parameters in your report with the current class-type. And then you can use ist like

$P{YourParamName1} for query, calculations or whatever you like....

 

that's all

 

hth

C-Box

 

 

 

 

 

 

 

By: Marc - kantspel

RE: Help with passing parameters from java

2004-08-17 08:57

Hi!

 

Thank you so much for your response. Using these methods are kind of confusing. :S

 

In this line here:

JasperPrint jasperPrint = JasperFillManager.fillReport(myRep, parameters, yourGetMethodForConnectionRetrieval());

what does myRep mean?

 

thanks

marc

 

 

 

 

By: Marc - kantspel

RE: Help with passing parameters from java

2004-08-17 17:38

Oh

I'm a total idiot :S

Thanks!

Marc

 

 

 

 

By: Marc - kantspel

RE: Help with passing parameters from java

2004-08-17 19:44

Hello!

 

I have another question.

This code runs until the line:

JasperReport myRep = (JasperReport) JRLoader.loadObject(fileNameOfMyReportAsJasper);

where I get the following exception:

[ERROR] Tue. 8:42:24.875 p.m. - From Class [reports.OrderForms], From Method [execute] - JRException: net.sf.jasperreports.engine.JRException: Error loading object from file : C:Program FilesApache GroupTomcat 4.1webappsdwPlugsreportsOrderForm.jasper

 

Why would this occur?

 

Thanks

Marc

 

 

 

 

By: Juby Victor - jubyvictor

RE: Help with passing parameters from java

2004-08-17 21:02

Instead of

JasperReport myRep = (JasperReport) JRLoader.loadObject(fileNameOfMyReportAsJasper);

 

try

JasperReport myRep = JasperManager.loadReport(fileNameOfMyReportAsJasper)

 

The problem maybe caused because the .jasper file you are trying to load may not have been serialized properly or got corrupted... just a wild guess he he

 

 

 

 

 

By: Marc - kantspel

RE: Help with passing parameters from java

2004-08-17 21:13

Hi

 

I totally appreciate all the help you are giving me!

 

Unfortunately, that didn't fix it. However, it did give me a new exception:

[ERROR] Tue. 10:10:32.062 p.m. - From Class [reports.OrderForms], From Method [execute] - JRException: net.sf.jasperreports.engine.JRException: Class not found when loading object from file : C:Program FilesApache GroupTomcat 4.1webappsdwPlugsreportsOrderForm.jasper

and it displays a java.lang.NullPointerException in the browser.

 

Any other guesses? :D

Thanks again

Marc

 

 

 

 

By: Juby Victor - jubyvictor

RE: Help with passing parameters from java

2004-08-17 21:17

Can u post the whole code ???

also a comsiderable amount of the error log

I want to know wtr u r using a pre-compiled .jasper file or loading the XML design the

 

 

 

 

By: Juby Victor - jubyvictor

RE: Help with passing parameters from java

2004-08-17 21:21

Hi

Is the .jasper file there in your CLASSPATH ?

 

 

 

 

By: Marc - kantspel

RE: Help with passing parameters from java

2004-08-17 21:34

ok here is my whole action:

package reports;

 

import java.io.IOException;

import net.sf.jasperreports.engine.JRException;

import java.util.HashMap;

import net.sf.jasperreports.view.*;

import net.sf.jasperreports.engine.util.*;

import net.sf.jasperreports.engine.*;

import javax.servlet.http.*;

import org.apache.struts.action.*;

import java.sql.*;

import utilities.*;

import beans.*;

 

public final class OrderForms extends Action

{

public ActionForward execute(ActionMapping mapping, ActionForm form,

HttpServletRequest request, HttpServletResponse response)

{

ActionForward nextPage = null;

DBConnectionManager conMan = null;

Connection dbConn = null;

int orderID = 4;

 

try

{

conMan = DBConnectionManager.getInstance();

dbConn = conMan.getConnection("dwPlugs");

dbConn.setAutoCommit(false);

 

String report = "C:\Program Files\Apache Group\Tomcat 4.1\webapps\dwPlugs\reports\OrderForm.jasper";

JasperReport myRep = JasperManager.loadReport(report);

HashMap parameters = new HashMap();

parameters.put("orderID", String.valueOf(orderID));

JasperPrint jasperPrint = JasperFillManager.fillReport(myRep, parameters, dbConn);

 

dbConn.commit();

dbConn.setAutoCommit(true);

conMan.freeConnection("dwPlugs",dbConn);

nextPage = mapping.findForward("success");

}

catch (SQLException sqle)

{

TextLogger.error("SQL Error in InventoriesActionAdd: " + sqle);

try

{

dbConn.rollback();

dbConn.setAutoCommit(true);

conMan.freeConnection("dwPlugs",dbConn);

}

catch (SQLException sqle2)

{

TextLogger.error("SQL Error in InventoriesActionAdd rollback: " + sqle2);

}

nextPage = mapping.findForward("failure");

}

catch (JRException e)

{

TextLogger.error("JRException: " + e);

}

 

return nextPage;

}

}

 

 

 

and here is the error:

 

HTTP Status 500 -

 

--------------------------------------------------------------------------------

 

type Exception report

 

message

 

description The server encountered an internal error () that prevented it from fulfilling this request.

 

exception

 

javax.servlet.ServletException

at org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:545)

at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:486)

at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)

at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)

at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)

at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2417)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)

at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)

at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:193)

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:781)

at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:549)

at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:589)

at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666)

at java.lang.Thread.run(Thread.java:536)

 

 

root cause

 

java.lang.NullPointerException

at reports.OrderForms.execute(OrderForms.java:33)

at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)

at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)

at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)

at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)

at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2417)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)

at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)

at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:193)

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:781)

at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:549)

at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:589)

at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666)

at java.lang.Thread.run(Thread.java:536)

 

 

 

--------------------------------------------------------------------------------

 

Apache Tomcat/4.1.29

 

 

 

No my .jasper file isn't in my classpath....does it have to be?

 

 

 

 

By: Marc - kantspel

RE: Help with passing parameters from java

2004-08-17 21:36

hrm posting the message screwed up the formatting of the code :S

hope it's not too hard to read :)

 

 

 

 

By: Marc - kantspel

RE: Help with passing parameters from java

2004-08-17 21:38

sorry i forgot to post that i also use a textlogger, and here is the exception error i get:

 

[ERROR] Tue. 10:21:23.640 p.m. - From Class [reports.OrderForms], From Method [execute] - JRException: net.sf.jasperreports.engine.JRException: Class not found when loading object from file : C:Program FilesApache GroupTomcat 4.1webappsdwPlugsreportsOrderForm.jasper

 

 

 

 

By: Juby Victor - jubyvictor

RE: Help with passing parameters from java

2004-08-17 21:52

Make sure you have the .jasper also available to tomcat maybe thats the prob , the code looks fine.

I would suggest to put .jasper in some folder in your webapp itself where tomcat can pick it up from ... bcoz its available in the context of the webapp then..

 

Looking at the logs i feel that tomcats not able to find the file , so obviously it must be a prob with the class path . Try writing a standalone core java app to do the same stuff and try executing it and see if it works..

 

also go through the webapps example in the demos of jasper reports. It will surely help

bye Good luck :)

 

 

 

 

By: Marc - kantspel

RE: Help with passing parameters from java

2004-08-17 21:57

OK thank you very much!!

I'll toy around with it.

 

Marc

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...