开发者

passing value dynamically to the JASPER API to generate a Report

I am generating the Report using the Jasper Reports . Inside the JRXML file in queryString , the query that is formed is

 SELECT * FROM Address WHERE city = $P{customerId}

Now inside my servlet please tell me how can i pass this value dy开发者_运维知识库namically ??

int custid  = Integer.parseInt(request.getParameter("customerId")) ;

Map parameters = new HashMap();

parameters.put("customerId", custid);

Please tell me is this the correct way of passing the data ??


You can implement your own datasource (must be net.sf.jasperreports.engine.JRDataSource interface implementation).

After filling (preparing) datasource it should be passed to the JasperFillManager.fillReport(java.lang.String sourceFileName, java.util.Map parameters, JRDataSource jrDataSource) method.

The sample:

    JRMapArrayDataSource dataSource = new JRMapArrayDataSource(data);
    JasperPrint jasperPrint = JasperFillManager.fillReport(sourceFileName, paramsMap, dataSource);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜