You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Andrew Mason <an...@assertis.net> on 2005/04/24 00:41:14 UTC

velocity config.getInitParameter()

Hi, 
I'm having some trouble getting a  Velocity Servlet to read an <init-param> 
from tomcat. So far i've tried the following:

public class SiteStructure extends VelocityServlet{
  private String base_dir = null;

protected Properties loadConfiguration(ServletConfig config) throws
 IOException,FileNotFoundException{

 ...
String path = config.getServletContext().getRealPath("/");
this.base_dir = config.getInitParameter("basedir");

   ...
}

in my web.xml file i've tried these two options, although not at the same 
time.

  <init-param>
                <param-name>basedir</param-name>
                <param-value>test</param-value>
   </init-param>
   
   <context-param>
                <param-name>basedir</param-name>
                <param-value>test</param-value>
        </context-param>

Its probably quite simple but i've looked all through both my tomcat books and 
velocity books and i can't see any  examples of this being done. The velocity 
docs say that the loadConfiguration() is called from init(), which is where 
all of the Tomcat servlet examples have called the getInitParameter() method 
from. 

Thanks in Advance
Andrew

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: velocity config.getInitParameter()

Posted by Andrew Mason <an...@assertis.net>.
Hi 
Thanks Shinobu,
Basically I found out that i needed to call the 
this.base_dir = config.getInitParameter("basedir"); method before I did 
anything else. 

I will have a look at the VelocityViewServlet though.

Thanks



On Monday 25 April 2005 19:47, Shinobu Kawai wrote:
> Hi Andrew,
>
> > I'm having some trouble getting a  Velocity Servlet to read an
> > <init-param> from tomcat. So far i've tried the following:
> >
> > public class SiteStructure extends VelocityServlet{
>
> First, I suggest using VelocityViewServlet, as VelocityServlet is
> deprecated and will be removed in future versions.
>     http://jakarta.apache.org/velocity/tools/view/index.html
>
> >  private String base_dir = null;
> >
> > protected Properties loadConfiguration(ServletConfig config) throws
> > IOException,FileNotFoundException{
> >
> > ...
> > String path = config.getServletContext().getRealPath("/");
> > this.base_dir = config.getInitParameter("basedir");
> >
> >   ...
> > }
> >
> > in my web.xml file i've tried these two options, although not at the same
> > time.
> >
> >  <init-param>
> >                <param-name>basedir</param-name>
> >                <param-value>test</param-value>
> >   </init-param>
> >
> >   <context-param>
> >                <param-name>basedir</param-name>
> >                <param-value>test</param-value>
> >        </context-param>
> >
> > Its probably quite simple but i've looked all through both my tomcat
> > books and velocity books and i can't see any  examples of this being
> > done. The velocity docs say that the loadConfiguration() is called from
> > init(), which is where all of the Tomcat servlet examples have called the
> > getInitParameter() method from.
>
> I don't see anything wrong so far, but I can't tell until I see all
> the relevant code.  Does it work with a regular servlet?
>
> Best regards,
> -- Shinobu
>
> --
> Shinobu Kawai <sh...@gmail.com>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: velocity config.getInitParameter()

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Andrew,

> I'm having some trouble getting a  Velocity Servlet to read an <init-param>
> from tomcat. So far i've tried the following:
> 
> public class SiteStructure extends VelocityServlet{

First, I suggest using VelocityViewServlet, as VelocityServlet is
deprecated and will be removed in future versions.
    http://jakarta.apache.org/velocity/tools/view/index.html

>  private String base_dir = null;
> 
> protected Properties loadConfiguration(ServletConfig config) throws
> IOException,FileNotFoundException{
> 
> ...
> String path = config.getServletContext().getRealPath("/");
> this.base_dir = config.getInitParameter("basedir");
> 
>   ...
> }
> 
> in my web.xml file i've tried these two options, although not at the same
> time.
> 
>  <init-param>
>                <param-name>basedir</param-name>
>                <param-value>test</param-value>
>   </init-param>
> 
>   <context-param>
>                <param-name>basedir</param-name>
>                <param-value>test</param-value>
>        </context-param>
> 
> Its probably quite simple but i've looked all through both my tomcat books and
> velocity books and i can't see any  examples of this being done. The velocity
> docs say that the loadConfiguration() is called from init(), which is where
> all of the Tomcat servlet examples have called the getInitParameter() method
> from.

I don't see anything wrong so far, but I can't tell until I see all
the relevant code.  Does it work with a regular servlet?

Best regards,
-- Shinobu

--
Shinobu Kawai <sh...@gmail.com>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org