You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Keng Wong <ke...@verizon.net> on 2001/05/12 01:55:32 UTC

Loading velocity.properties from Global Context

I am trying to load the velocity.properties file from the context instead of
from each servlet declaration (<servlet><init-param>...):
<web-app>
  <context-param>
    <param-name>properties</param-name>
    <param-value>/WEB-INF/conf/velocity.properties</param-value>
  </context-param>
</web-app>

I can't seem to load the file at all. However, putting that in a
<init-param> within a <servlet> tag works. Any way around this ? I had a
couple of servlets that extends VelocityServlet and do not wish to add the
mappings for each servlet.

Thanks.

-keng


Re: Loading velocity.properties from Global Context

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Keng Wong wrote:
> 
> Thanks Geir. I thought of this too, but will there be a race issue if the
> servlet engine is restarted and requests comes in to other servlets before
> the 'init-servlet' is done initializing ?

No - the <load-on-startup> initialization stuff should happen before
requests are sent to the webapp - at least thats my understanding.  I
requested clarification from Sun's Servlet spec group on this issue, and
it was said that this is true, and will hopefully be clarified in the
2.3 spec.

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
"still climbing up to the shoulders..."

RE: Loading velocity.properties from Global Context

Posted by Keng Wong <ke...@verizon.net>.
Thanks Geir. I thought of this too, but will there be a race issue if the
servlet engine is restarted and requests comes in to other servlets before
the 'init-servlet' is done initializing ?

> -----Original Message-----
> I was playing with this, and couldn't get it to work either w/ Tomcat
> 3.2.1 - however, I didn't play very long.
>
> Once strategy that I use to solve this problem is in your webapp
> specific web.xml in WEB-INF, I make one of the servlets
> <load-on-startup>, so it takes care of the Velocity initialization for
> you.
>
> You only need to do it once - once any of your servlets initializes
> Velocity in a webapp, then the Velocity runtime will be ready for all.
> Thats why the single servlet <load-on-startup> technique works.


RE: Loading velocity.properties from Global Context

Posted by David Esposito <es...@newnetco.com>.
This is the little snippet of code that we use to pull init parameters out
of our web.xml ... first it looks for the init param in the specific servlet
<init-param> block ... otherwise it looks at the <context-params> dunno if
you tried this:

protected String getInitParam(String parameterName)
{
	String retVal = null;

	//First check to see if the value was specified on a servlet-specific basis
	if(getServletConfig().getInitParameter(parameterName) != null)
		retVal = getServletConfig().getInitParameter(parameterName);
	//Else, let's see if its set on an context-wide basis
	else
		retVal = getServletContext().getInitParameter(parameterName);

	return retVal;
}

(this has been tested using Tomcat and Jetty ... and we actually use the
load-on-startup trick too ... )

> -----Original Message-----
> From: gmj@mta8.srv.hcvlny.cv.net [mailto:gmj@mta8.srv.hcvlny.cv.net]On
> Behalf Of Geir Magnusson Jr.
> Sent: Thursday, May 17, 2001 7:07 AM
> To: velocity-user@jakarta.apache.org
> Subject: Re: Loading velocity.properties from Global Context
>
>
> Keng Wong wrote:
> >
> > I am trying to load the velocity.properties file from the
> context instead of
> > from each servlet declaration (<servlet><init-param>...):
> > <web-app>
> >   <context-param>
> >     <param-name>properties</param-name>
> >     <param-value>/WEB-INF/conf/velocity.properties</param-value>
> >   </context-param>
> > </web-app>
> >
> > I can't seem to load the file at all. However, putting that in a
> > <init-param> within a <servlet> tag works. Any way around this ? I had a
> > couple of servlets that extends VelocityServlet and do not wish
> to add the
> > mappings for each servlet.
>
> I was playing with this, and couldn't get it to work either w/ Tomcat
> 3.2.1 - however, I didn't play very long.
>
> Once strategy that I use to solve this problem is in your webapp
> specific web.xml in WEB-INF, I make one of the servlets
> <load-on-startup>, so it takes care of the Velocity initialization for
> you.
>
> You only need to do it once - once any of your servlets initializes
> Velocity in a webapp, then the Velocity runtime will be ready for all.
> Thats why the single servlet <load-on-startup> technique works.
>
>
> geir
>
> --
> Geir Magnusson Jr.                           geirm@optonline.net
> System and Software Consulting
> Developing for the web?  See http://jakarta.apache.org/velocity/
> "still climbing up to the shoulders..."


Re: Loading velocity.properties from Global Context

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Keng Wong wrote:
> 
> I am trying to load the velocity.properties file from the context instead of
> from each servlet declaration (<servlet><init-param>...):
> <web-app>
>   <context-param>
>     <param-name>properties</param-name>
>     <param-value>/WEB-INF/conf/velocity.properties</param-value>
>   </context-param>
> </web-app>
> 
> I can't seem to load the file at all. However, putting that in a
> <init-param> within a <servlet> tag works. Any way around this ? I had a
> couple of servlets that extends VelocityServlet and do not wish to add the
> mappings for each servlet.

I was playing with this, and couldn't get it to work either w/ Tomcat
3.2.1 - however, I didn't play very long.

Once strategy that I use to solve this problem is in your webapp
specific web.xml in WEB-INF, I make one of the servlets
<load-on-startup>, so it takes care of the Velocity initialization for
you.

You only need to do it once - once any of your servlets initializes
Velocity in a webapp, then the Velocity runtime will be ready for all. 
Thats why the single servlet <load-on-startup> technique works.


geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
"still climbing up to the shoulders..."