You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "Geir Magnusson Jr." <ge...@optonline.net> on 2002/05/27 13:55:03 UTC

Re: Velocity w/Tomcat Servlet

On 5/27/02 5:50 AM, "Chris Lee" <Ch...@centurycity.com.hk> wrote:

> Hi,
> 
> Config: Tomcat  4.03,  Velocity 1.3 rc-1,  Windows 2000
> 
> I create a new servlet named rhicls:
> 
> at server.xml, I add new context
> 
> <Context path="/rhicls"
> docBase="rhicls"
> crossContext="false"
> debug="0"
> reloadable="true" >
> </Context>
> 
> As I want to change template path, so I create web.xml on rhicls\WEB-INF
> folder.
> 
> <?xml version="1.0" encoding="ISO-8859-1"?>
> 
> <!DOCTYPE web-app
>   PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
>   "http://java.sun.com/dtd/web-app_2_3.dtd">
> 
> <web-app>
> <servlet>
>   <init-param>
>     <param-name>properties</param-name>
>     <param-value>velocity.properties</param-value>
>   </init-param>
> </servlet>
> </web-app>
> 
> This is velocity.properties on rhicls\WEB-INF\ folder.
> 
> file.resource.loader.path=/templates
> runtime.log=/WEB-INF/logs/velocity.log
> 
> However, it seems that the Velocity did not read the file and use the
> default Template path. What's wrong with it?

Well, a few things.  The Velocity servlet, if left 'as-is', will take the
value of properties and use as is in the Velocity engine.  The velocity
engine, which itself knows nothing about webapps, will assume 'current
directory' for any relative pathname (of which 'velocity.properties' is one
of them.)

The solution?

Take  a look at examples/servlet_example2 and see how the init() code
figures out how to find the file relative to the webapp root.  It does the
same for file path and runtime log, IIRC.

Geir

P.s.  This is pre-coffee, so YMMV

-- 
Geir Magnusson Jr.
Research & Development, Adeptra Inc.
geirm@adeptra.com
+1-203-247-1713



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>