velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nathan Bubna <>
Subject Re: newbie - can't get VelocityServlet to read configuration file
Date Wed, 17 Aug 2005 17:28:59 GMT
On 8/17/05, James Closs <> wrote:
> On 15 Aug 2005, at 23:18, Nathan Bubna wrote:
> > as for your original problem, something odd is going on (probably in
> > your use of velocity) if the properties file is being read, but makes
> > no difference.
> >
> > tell me, are you using the singleton (Velocity.blahblah) or not
> > (VelocityEngine.blahblah) in your servlet?  and what is it that tells
> > you that the properties are making no difference?
> Hi everyone,
> Firstly, thank you all for your very helpful responses.
> I have made a good deal of progress - switched my code to using
> VelocityViewServlet and it now appears to be loading the properties
> file correctly. I think the problem was actually in my layout of
> web.xml where I had got <servlet> and <servlet-mapping> blocks in the
> wrong order (noob I know!)
> I had one question regarding VelocityViewServlet and Velocity and the
> use of sessions in general. Am I right in presuming that the context
> used in VelocityViewServlet will not be consistent across page views
> within the same session, and if it is not is the 'best' way to access
> session attributes simply by $session.getAttribute("")?

first off... yes, the VVS will give you a new context for each request
(aka "page view").  that is a correct presumption.

second, one of the cool things that the VVS uses is a ChainedContext
that will automagically "expose" request, session, and servlet context
attributes to the template designer.   so for instance, if one of your
servlets does session.setAttribute("foo", new Foo());  then in your
templates, you can access the attribute by just doing $foo instead of

this makes it really easy for your servlets and/or filters to make
things available to the templates w/o having to get access to the
actual Context object created by the VVS.  it also makes the templates

oh, and be sure to check out the toolbox support too.  it is a great
way to define a very clear, consistent, and powerful interface for all
of your templates.  (a lot better than doing request.setAttribute(...)
throughout your servlets.)

> I do not see myself setting session attributes from within the VTL
> itself but will have other servlets (that handle login/registration
> etc) that do this and then redirect to velocity templates. A simple
> example would be setting an error message attribute and then
> redirecting to a velocity template for the error page.
> ps It's really a pretty simple project that I'm working on so I'm not
> really going to be looking at any more complex frameworks.

the VVS will probably be plenty of power for you then.  it's got a
pretty easy learning curve and can take you pretty far.  the only
recommendation i might make is that if you are planning much database
interaction, you might consider looking up a project called Velosurf. 
it's a pretty simple database access tool specifically designed for
use with the VelocityView project.

> best
> ====
> James Closs, Director, bitBull Ltd
> 07771 991171
> ====
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message