You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Gregg Bolinger <gr...@javaranch.com> on 2004/03/12 17:50:00 UTC

Switching to VVS

I am trying to switch to using the VVS and now I can't located my 
template files.

Other than extending VVS instead of VS, I only made one change.  I 
changed from

file.resource.loader.path

to

webapp.resource.loader.path

in my velocity.properties file.  And here is my test servlet mapping in 
my web.xml

<servlet>
        <servlet-name>index</servlet-name>
        <servlet-class>com.test.IndexServlet</servlet-class>
        <init-param>
            <param-name>org.apache.velocity.properties</param-name>
            <param-value>/WEB-INF/velocity.properties</param-value>
        </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>index</servlet-name>
        <url-pattern>/index</url-pattern>
    </servlet-mapping>

Nothing else changed.  VS works.  VVS doesn't.  It tells me it can't 
find my index.htm which is my template file.  Is there something else I 
need to change.

Also, I had to find out about the change to the velocity.properties file 
in the mailing list archives.  Can anyone point me to a link of all the 
CURRENT available property options?

Thanks.


-- 
Gregg Bolinger
My Weblog <http://www.gthought.com/blog>


---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 0403-7, 03/11/2004
Tested on: 3/12/2004 10:50:05 AM
avast! is copyright (c) 2000-2003 ALWIL Software.
http://www.avast.com




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


Re: Switching to VVS

Posted by Nathan Bubna <na...@esha.com>.
Gregg Bolinger said:
> I bet that was in the documentation and/or javadocs huh.  LOL

well, it's in the WebappLoader javadocs, but i'm not sure we mention it
elsewhere.  more/better documentation could never hurt.

> Works great now!  Thanks.
...

glad to hear it. :)

Nathan Bubna
nathan@esha.com


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


Re: Switching to VVS

Posted by Gregg Bolinger <gr...@javaranch.com>.
I bet that was in the documentation and/or javadocs huh.  LOL

Works great now!  Thanks.

Gregg

Nathan Bubna wrote:

>Gregg Bolinger said:
>...
>  
>
>>velocity.properties
>>
>>webapp.resource.loader.path =
>>c:/programs/tomcat/webapps/anykey/WEB-INF/templates
>>    
>>
>
>here's the problem.  the webapp loader is not the file resource loader.  it
>uses the webapp as it's root, not the local computer's file system.  this
>makes VelocityView apps much easier to move around and lets us package them in
>WARs and other cool things like that.
>
>try
>
>webapp.resource.loader.path=/WEB-INF/templates
>
>...
>  
>
>>And I get this cool error when trying to access..
>>
>>Unable to find resource '/index.htm'
>>
>>org.apache.velocity.exception.ResourceNotFoundException:
>>Unable to find resource '/index.htm'
>>    
>>
>...
>
>and then these cool errors should disappear!
>
>Nathan Bubna
>nathan@esha.com
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
>
>
>
>---
>avast! Antivirus: Inbound message clean.
>Virus Database (VPS): 0403-7, 03/11/2004
>Tested on: 3/12/2004 11:51:01 AM
>avast! is copyright (c) 2000-2003 ALWIL Software.
>http://www.avast.com
>
>
>
>
>  
>

-- 
Gregg Bolinger
My Weblog <http://www.gthought.com/blog>


---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 0403-7, 03/11/2004
Tested on: 3/12/2004 11:55:55 AM
avast! is copyright (c) 2000-2003 ALWIL Software.
http://www.avast.com




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


Re: Switching to VVS

Posted by Nathan Bubna <na...@esha.com>.
Gregg Bolinger said:
...
> velocity.properties
>
> webapp.resource.loader.path =
> c:/programs/tomcat/webapps/anykey/WEB-INF/templates

here's the problem.  the webapp loader is not the file resource loader.  it
uses the webapp as it's root, not the local computer's file system.  this
makes VelocityView apps much easier to move around and lets us package them in
WARs and other cool things like that.

try

webapp.resource.loader.path=/WEB-INF/templates

...
> And I get this cool error when trying to access..
>
> Unable to find resource '/index.htm'
>
> org.apache.velocity.exception.ResourceNotFoundException:
> Unable to find resource '/index.htm'
...

and then these cool errors should disappear!

Nathan Bubna
nathan@esha.com


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


Re: Switching to VVS

Posted by Gregg Bolinger <gr...@javaranch.com>.
Ok, let's start kind of fresh.  I decided to do this the "suggested" 
way, so here is what I am doing.  My servlets simply extend HttpServlet 
now.  Nothing fancy.  Now I will show you my files.

web.xml

<servlet>
        <servlet-name>velocity</servlet-name>
        
<servlet-class>org.apache.velocity.tools.view.servlet.VelocityViewServlet</servlet-class>
        <init-param>
            <param-name>org.apache.velocity.properties</param-name>
            <param-value>/WEB-INF/velocity.properties</param-value>
        </init-param>
        <load-on-startup>10</load-on-startup>
    </servlet>

    <servlet>
        <servlet-name>index</servlet-name>
        <servlet-class>com.test.IndexServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>velocity</servlet-name>
        <url-pattern>*.htm</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>index</servlet-name>
        <url-pattern>/index</url-pattern>
    </servlet-mapping>

velocity.properties

webapp.resource.loader.path = 
c:/programs/tomcat/webapps/anykey/WEB-INF/templates

IndexServlet.java

public class IndexServlet extends HttpServlet
{

    public void doGet(HttpServletRequest request, HttpServletResponse 
response) throws IOException, ServletException
    {
        doPost(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse 
response) throws IOException, ServletException
    {
         
this.getServletContext().getRequestDispatcher("/index.htm").forward(request, 
response);
    }

}

And I get this cool error when trying to access..

Unable to find resource '/index.htm'

org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource '/index.htm'
....
....

Thanks.

Gregg



Nathan Bubna wrote:

>Gregg Bolinger said:
>  
>
>>I am trying to switch to using the VVS and now I can't located my
>>template files.
>>
>>Other than extending VVS instead of VS, I only made one change.  I
>>changed from
>>
>>file.resource.loader.path
>>
>>to
>>
>>webapp.resource.loader.path
>>    
>>
>
>what are the rest of your resource.loader properties?
>in particular, are you setting
>
>resource.loader=<some name>
>
>try commenting out all your resource loader properties except for
>
>webapp.resource.loader.path
>
>  
>
>>in my velocity.properties file.  And here is my test servlet mapping in
>>my web.xml
>>
>><servlet>
>>        <servlet-name>index</servlet-name>
>>        <servlet-class>com.test.IndexServlet</servlet-class>
>>    
>>
>
>what does IndexServlet do?  are there VVS methods does it overrides?
>
>  
>
>>        <init-param>
>>            <param-name>org.apache.velocity.properties</param-name>
>>            <param-value>/WEB-INF/velocity.properties</param-value>
>>        </init-param>
>>    </servlet>
>>
>>    <servlet-mapping>
>>        <servlet-name>index</servlet-name>
>>        <url-pattern>/index</url-pattern>
>>    </servlet-mapping>
>>
>>Nothing else changed.  VS works.  VVS doesn't.  It tells me it can't
>>find my index.htm
>>    
>>
>
>why not just map *.htm or /index*?  don't you need either an exact match or a
>wildcard?
>
>also, you say "it tells me it can't find..."  what exactly is "it"?  Tomcat?
>VVS?
>
>  
>
>>which is my template file.  Is there something else I
>>need to change.
>>
>>Also, I had to find out about the change to the velocity.properties file
>>in the mailing list archives.  Can anyone point me to a link of all the
>>CURRENT available property options?
>>    
>>
>
>if you mean velocity.property options, they're pretty much the same for the
>VVS as any other velocity application, with the exception that the VVS will
>automatically set
>
>resource.loader=webapp
>webapp.resource.loader.class=org.apache.velocity.tools.view.servlet.WebappLoad
>er
>
>and will also manually set logging to the ServletLogger (i don't remember the
>logsystem property name offhand and won't try).
>
>these properties are set before loading your velocity.properties to allow you
>to override them.  so if you set resource.loader=file in your props, then it
>won't register the webapp loader.  you need to either not set it or else set
>resource.loader=webapp,file
>
>oh, and the VelocityLayoutServlet does have extra velocity.properties, but
>those are documented.
>
>Nathan Bubna
>nathan@esha.com
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
>
>
>
>---
>avast! Antivirus: Inbound message clean.
>Virus Database (VPS): 0403-7, 03/11/2004
>Tested on: 3/12/2004 11:32:00 AM
>avast! is copyright (c) 2000-2003 ALWIL Software.
>http://www.avast.com
>
>
>
>
>  
>

-- 
Gregg Bolinger
My Weblog <http://www.gthought.com/blog>


---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 0403-7, 03/11/2004
Tested on: 3/12/2004 11:44:14 AM
avast! is copyright (c) 2000-2003 ALWIL Software.
http://www.avast.com




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


Re: Switching to VVS

Posted by Nathan Bubna <na...@esha.com>.
Gregg Bolinger said:
> I am trying to switch to using the VVS and now I can't located my
> template files.
>
> Other than extending VVS instead of VS, I only made one change.  I
> changed from
>
> file.resource.loader.path
>
> to
>
> webapp.resource.loader.path

what are the rest of your resource.loader properties?
in particular, are you setting

resource.loader=<some name>

try commenting out all your resource loader properties except for

webapp.resource.loader.path

> in my velocity.properties file.  And here is my test servlet mapping in
> my web.xml
>
> <servlet>
>         <servlet-name>index</servlet-name>
>         <servlet-class>com.test.IndexServlet</servlet-class>

what does IndexServlet do?  are there VVS methods does it overrides?

>         <init-param>
>             <param-name>org.apache.velocity.properties</param-name>
>             <param-value>/WEB-INF/velocity.properties</param-value>
>         </init-param>
>     </servlet>
>
>     <servlet-mapping>
>         <servlet-name>index</servlet-name>
>         <url-pattern>/index</url-pattern>
>     </servlet-mapping>
>
> Nothing else changed.  VS works.  VVS doesn't.  It tells me it can't
> find my index.htm

why not just map *.htm or /index*?  don't you need either an exact match or a
wildcard?

also, you say "it tells me it can't find..."  what exactly is "it"?  Tomcat?
VVS?

> which is my template file.  Is there something else I
> need to change.
>
> Also, I had to find out about the change to the velocity.properties file
> in the mailing list archives.  Can anyone point me to a link of all the
> CURRENT available property options?

if you mean velocity.property options, they're pretty much the same for the
VVS as any other velocity application, with the exception that the VVS will
automatically set

resource.loader=webapp
webapp.resource.loader.class=org.apache.velocity.tools.view.servlet.WebappLoad
er

and will also manually set logging to the ServletLogger (i don't remember the
logsystem property name offhand and won't try).

these properties are set before loading your velocity.properties to allow you
to override them.  so if you set resource.loader=file in your props, then it
won't register the webapp loader.  you need to either not set it or else set
resource.loader=webapp,file

oh, and the VelocityLayoutServlet does have extra velocity.properties, but
those are documented.

Nathan Bubna
nathan@esha.com


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


Re: Switching to VVS

Posted by Nathan Bubna <na...@esha.com>.
Gregg Bolinger said:
> Well, the problem is I am not mapping that to a velocity template.
> index is a Servlet.  The Servlet extends VVS and returns a Template on
> the handleRequest.  So what I did is correct for what I am trying to
> do.  It works fine with VS.

ah.  yeah, that should work for the VVS as well (assuming your resource.loader
properties are correct), but you should know that that's not the standard
practice (which is a lot easier, IMHO).  :)

Nathan Bubna
nathan@esha.com


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


Re: Switching to VVS

Posted by Gregg Bolinger <gr...@javaranch.com>.
Well, the problem is I am not mapping that to a velocity template.  
index is a Servlet.  The Servlet extends VVS and returns a Template on 
the handleRequest.  So what I did is correct for what I am trying to 
do.  It works fine with VS.

Thanks Mike.

Gregg

Mike Curwen wrote:

><url-pattern>/index.htm</url-pattern>
> or
><url-pattern>*.htm</url-pattern>
>
>I think is the usage pattern for VVS.
>
>
>  
>
>>-----Original Message-----
>>From: Gregg Bolinger [mailto:gregg@javaranch.com] 
>>Sent: Friday, March 12, 2004 10:50 AM
>>To: velocity-user@jakarta.apache.org
>>Subject: Switching to VVS
>>
>>
>>I am trying to switch to using the VVS and now I can't located my 
>>template files.
>>
>>Other than extending VVS instead of VS, I only made one change.  I 
>>changed from
>>
>>file.resource.loader.path
>>
>>to
>>
>>webapp.resource.loader.path
>>
>>in my velocity.properties file.  And here is my test servlet 
>>mapping in 
>>my web.xml
>>
>><servlet>
>>        <servlet-name>index</servlet-name>
>>        <servlet-class>com.test.IndexServlet</servlet-class>
>>        <init-param>
>>            <param-name>org.apache.velocity.properties</param-name>
>>            <param-value>/WEB-INF/velocity.properties</param-value>
>>        </init-param>
>>    </servlet>
>>
>>    <servlet-mapping>
>>        <servlet-name>index</servlet-name>
>>        <url-pattern>/index</url-pattern>
>>    </servlet-mapping>
>>
>>Nothing else changed.  VS works.  VVS doesn't.  It tells me it can't 
>>find my index.htm which is my template file.  Is there 
>>something else I 
>>need to change.
>>
>>Also, I had to find out about the change to the 
>>velocity.properties file 
>>in the mailing list archives.  Can anyone point me to a link 
>>of all the 
>>CURRENT available property options?
>>
>>Thanks.
>>
>>
>>-- 
>>Gregg Bolinger
>>My Weblog <http://www.gthought.com/blog>
>>
>>
>>    
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
>
>
>
>---
>avast! Antivirus: Inbound message clean.
>Virus Database (VPS): 0403-7, 03/11/2004
>Tested on: 3/12/2004 11:09:00 AM
>avast! is copyright (c) 2000-2003 ALWIL Software.
>http://www.avast.com
>
>
>
>
>  
>

-- 
Gregg Bolinger
My Weblog <http://www.gthought.com/blog>


---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 0403-7, 03/11/2004
Tested on: 3/12/2004 11:11:20 AM
avast! is copyright (c) 2000-2003 ALWIL Software.
http://www.avast.com




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


RE: Switching to VVS

Posted by Mike Curwen <gb...@gb-im.com>.
<url-pattern>/index.htm</url-pattern>
 or
<url-pattern>*.htm</url-pattern>

I think is the usage pattern for VVS.


> -----Original Message-----
> From: Gregg Bolinger [mailto:gregg@javaranch.com] 
> Sent: Friday, March 12, 2004 10:50 AM
> To: velocity-user@jakarta.apache.org
> Subject: Switching to VVS
> 
> 
> I am trying to switch to using the VVS and now I can't located my 
> template files.
> 
> Other than extending VVS instead of VS, I only made one change.  I 
> changed from
> 
> file.resource.loader.path
> 
> to
> 
> webapp.resource.loader.path
> 
> in my velocity.properties file.  And here is my test servlet 
> mapping in 
> my web.xml
> 
> <servlet>
>         <servlet-name>index</servlet-name>
>         <servlet-class>com.test.IndexServlet</servlet-class>
>         <init-param>
>             <param-name>org.apache.velocity.properties</param-name>
>             <param-value>/WEB-INF/velocity.properties</param-value>
>         </init-param>
>     </servlet>
> 
>     <servlet-mapping>
>         <servlet-name>index</servlet-name>
>         <url-pattern>/index</url-pattern>
>     </servlet-mapping>
> 
> Nothing else changed.  VS works.  VVS doesn't.  It tells me it can't 
> find my index.htm which is my template file.  Is there 
> something else I 
> need to change.
> 
> Also, I had to find out about the change to the 
> velocity.properties file 
> in the mailing list archives.  Can anyone point me to a link 
> of all the 
> CURRENT available property options?
> 
> Thanks.
> 
> 
> -- 
> Gregg Bolinger
> My Weblog <http://www.gthought.com/blog>
> 
> 


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