Jump to content
Changes to the Jaspersoft community edition download ×

Velocity and JasperReports


Recommended Posts

Hi guys, I'm new at java and jasper. I have created reports using JasperReports and iReport but have to make my reports more dynamic. Users should be able to select columns that should appear on report.

I have tried going thru the article- http://www.ibm.com/developerworks/websphere/library/techarticles/0505_olivieri/0505_olivieri.html

but have an error that reads - identify expected at this line :- BufferedWriter writer = new BufferedWriter(new, OutputStreamWriter(outStream));

here is the complete code:

import org.apache.velocity.Template;

import org.apache.velocity.app.Velocity;

import org.apache.velocity.context.Context;

import org.apache.velocity.exception.ParseErrorException;

import org.apache.velocity.exception.ResourceNotFoundException;

import org.apache.velocity.servlet.VelocityServlet;

import java.io.BufferedWriter;

import java.io.PipedInputStream;

import java.io.PipedOutputStream;




import javax.servlet.ServletConfig;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import java.util.Properties;

public class VelocityTest extends VelocityServlet {

protected Properties loadConfiguration(ServletConfig config) {

Properties properties = new Properties();

properties.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, config.getServletContext().getRealPath("/"));


return properties;



public Template handleRequest(HttpServletRequest request, HttpServletResponse response, Context context) {

context.put("sql","SELECT * from wcs.tblpayments");


context.put("title","testing Velocity");



Template template = null;

PipedInputStream inStream;

BufferedWriter writer ;

Thread thread;

PipedOutputStream outStream;

TemplateCompiler compiler;

try {

PipedOutputStream outStream = new PipedOutputStream();


BufferedWriter writer = new BufferedWriter(new, OutputStreamWriter(outStream));



// Connect input stream to output stream

inStream = new PipedInputStream(outStream);

compiler = new TemplateCompiler(inStream);

thread = new Thread(compiler);


template.merge(context, writer);

template = getTemplate("BasicReport.vm");


// tpl = getTemplate("hello.vm");

} catch (ResourceNotFoundException e) {


} catch (ParseErrorException e) {


} catch (Exception e) {


} finally {

if (writer != null) {






// Get compiled report

return (compiler.getJasperReport());







any assistance will be greatly appreciated

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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...