velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c_k...@bluemail.ch
Subject template isn't found within a jsp
Date Thu, 05 Sep 2002 21:03:38 GMT
Hello,
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:

----
<%
Velocity.init();

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
shows:

----
<%
Velocity.init();

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);
reader.close();
%>
----

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:   <mailto:velocity-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:velocity-user-help@jakarta.apache.org>


Mime
View raw message