You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Jonathan Knispel <jo...@nstc.nec.com.au> on 2001/06/25 03:11:47 UTC

VelocityServlets and init-params

G'day,

  I have a newbie question about VelocityServlets and properties.

  I'd like to set "file.resource.loader.path" to point to
WEB-INF/velocity/templates.  The developer guide section on servlet
deployment describes how to do this by adding a "properties"
<init-param> to a <servlet> element in the deployment descriptor
(web.xml).

  Presumably, "<load-on-startup>1</load-on-startup>" is used to ensure the
VelocityServlet with the properties is the first VelocityServlet loaded.
This prevents another VelocityServlet with no properties from preempting the
"chosen one" with the properties.  The singleton design pattern means the
properties are only loaded once.

  I wondered if it would be more elegant to have Velocity use a
<context-param> in the deployment descriptor rather than an <init-param> in
one of the servlets.  Something like this:

    <context-param>
        <param-name>velocityProperties</param-name>
        <param-value>WEB-INF/velocity/velocity.properties</param-value>
        <description>
            The location of the application-wide Jakarta Velocity
            properties for this web application.
        </description>
    </context-param>

That would prevent potential ordering problems associated with tying the
Velocity properties initialisation to a particular servlet.  It also seems a
more natural place to define an application-wide parameter.  The
VelocityServlet class would just use ServletContext.getInitParameter()
rather than ServletConfig.getInitParameter().

  This mechanism is compatible with the existing approach.  If the first
VelocityServlet to be loaded has an <init-param> for its properties, we
could simply load any properties from the <context-param> first, overlay the
servlet's properties then overlay the result on the default Velocity
properties.

  Is that a feasible approach?

Jonathan Knispel
Senior Software Design Engineer, NEC Australia
jonathank@nstc.nec.com.au


Re: VelocityServlets and init-params

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Jonathan Knispel wrote:
> 
>   I wondered if it would be more elegant to have Velocity use a
> <context-param> in the deployment descriptor rather than an <init-param> in
> one of the servlets.  Something like this:
> 
>     <context-param>
>         <param-name>velocityProperties</param-name>
>         <param-value>WEB-INF/velocity/velocity.properties</param-value>
>         <description>
>             The location of the application-wide Jakarta Velocity
>             properties for this web application.
>         </description>
>     </context-param>
> 
> That would prevent potential ordering problems associated with tying the
> Velocity properties initialisation to a particular servlet.  It also seems a
> more natural place to define an application-wide parameter.  The
> VelocityServlet class would just use ServletContext.getInitParameter()
> rather than ServletConfig.getInitParameter().
>  
>   Is that a feasible approach?

Yep!  Tha should work fine - except the param-name would be 'properties'
to be compatible with existing systems.

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
You have a genius for suggesting things I've come a cropper with!