velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject template isn't found within a jsp
Date Thu, 05 Sep 2002 21:03:38 GMT
I want to use velocity for the first time. In the users guide, it was explained
how to use velocity within a servlet. So I thought, I could use velocity
directly within a jsp but with the advantage, that I don't have to compile
the servlet each time I change the code. 
So I tried the following code:


VelocityContext context = new VelocityContext();
context.put( "name", "Hello World");

// i've also tried: application.getRealPath("/")+"vc_test.vm";
String templateName = "vc_test.vm";

Template template = Velocity.getTemplate(templateName);
template.merge( context, out);

there was always the same exception: Unable to find resource ...
So, I've tried to configure the resource loader (as described in the users
guide) by setting  file.resource.loader.path.
But I didn't work...

But the template is placed in the right directory, as the following workaround


VelocityContext context = new VelocityContext();
context.put( "name", "Hello World");

String templateName = application.getRealPath("/")+"vc_test.vm";

FileReader reader = new FileReader(templateName);
Velocity.evaluate( context, out, "", reader);

the example above works perfectly. But I wonder why the first code sample
doesn't work.
If it velocity can be used within a servlet, it must be possible to use
it within a jsp (without using the <vel:velocity> tag)

Cornel Koch

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message