velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Geir Magnusson Jr. <ge...@adeptra.com>
Subject Re: Re[2]: Newbie - Keep getting ResourceNotFoundException
Date Wed, 27 Nov 2002 19:33:19 GMT

On Wednesday, November 27, 2002, at 02:21 PM, Søren Neigaard wrote:

> Yes I figured it out myself, just had to read some more. Although I
> have been in the computer business for quite some time now, I still
> have a tendency to ask firs, and look last - sorry I know it's a bad
> habit :) Thanks for the answer though.

I do the same thing, btw.  It's a terrible habit. :)

>
> /Søren
>
> Wednesday, November 27, 2002, 6:17:47 PM, Geir wrote:
>
> GMJ> If you already solve the problem, ignore - my scan of the list 
> didn't
> GMJ> seem to have any help for you...
>
> GMJ> On Tuesday, November 26, 2002, at 02:36 PM, Søren Neigaard wrote:
>
>>> I'm trying to make a simple HelloWorld example, and I'm doing this
>>> from inside the doGet method in a servlet:
>>>
>>> ------------------
>>> Velocity.init();
>>> VelocityContext context = new VelocityContext();
>>> context.put("name", new String("Velocity Test"));
>>> Template template = null;
>>> try {
>>>   template = Velocity.getTemplate("mytemplate.vm");
>>>   template.merge(context,response.getWriter());
>>> }
>>> catch(Exception e){
>>>   e.printStackTrace();
>>> }
>>> ------------------
>>>
>>> Where does it look for the template? Can it be on the file system, or
>>> must it be accessible via HTTP? I have now tried to pint it directly
>>> to the path where the file is, and i get this error:
>>>
>>> ------------------
>>> org.apache.velocity.exception.ResourceNotFoundException: Unable to
>>> find resource
>>> '/C:/jakarta-tomcat-4.1.10-LE-jdk14/webapps/yaf/mytemplate.vm'
>>> ------------------
>>>
>>> And the file is there!? Please advice, what is my (simple) problem?
>
> GMJ> It's a simple problem.
>
> GMJ> First, some comments :
>
> GMJ> 1) you don't want to put init() in the doGet().  First, it's not 
> going
> GMJ> to work after the first time, and two, it's much better to put 
> this
> GMJ> into the servlets' init method, so it will get called at the 
> right time
> GMJ> in the servlet life cycle.
>
> GMJ> 2) There is nothing wrong with rolling your own servlet - it's 
> what I
> GMJ> do and can customize things the way I want them to be.  
> VelocityServlet
> GMJ> is a nice base, and it has a nice model to work with, but there 
> are
> GMJ> many ways to do it.
>
> GMJ> 3) The problem - the problem is that by default, velocity's 
> resource
> GMJ> loader is the FileResourceLoader, and further, it defaults to the
> GMJ> 'current directory', whatever that is, when init()-ed w/o 
> parameters.
> GMJ> The solution is really simple - you want to set the file resource
> GMJ> loader path with the right thing - see how VelocityServlet does 
> it, or
> GMJ> the servlet examples in the distro.
>
> GMJ> Other solutions is to use the webapp resource loader from the 
> tools
> GMJ> project as well, as that is meant to not depend on the filesystem,
> GMJ> which is the better thing to do in a servlet environment.
>
> GMJ> geir
>
>
> --
> To unsubscribe, e-mail:   
> <mailto:velocity-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: 
> <mailto:velocity-user-help@jakarta.apache.org>
>
>
-- 
Geir Magnusson Jr                                   203-355-2219(w)
Adeptra, Inc.                                       203-247-1713(m)
geirm@adeptra.com


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


Mime
View raw message