velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nick Temple" <ntem...@alivecity.com>
Subject RE: template isn't found within a jsp
Date Thu, 05 Sep 2002 23:02:58 GMT
I used this method in the initial conversion to Velocity so that the "links"
to the JSP's didn't break.

Try something like:

VelocityEngine ve = new VelocityEngine();
Properties p = new Properties();
p.setProperty("file.resource.loader.path", "d:/path/to/my/templates");
ve.init(p);


-----Original Message-----
From: c_koch@bluemail.ch [mailto:c_koch@bluemail.ch]
Sent: Thursday, September 05, 2002 4:04 PM
To: velocity-user@jakarta.apache.org
Subject: template isn't found within a jsp


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>



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