velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dan Nicolici <dan.nicol...@nexource.ro>
Subject Re: Webapp resource loader problem
Date Thu, 03 May 2007 06:10:59 GMT
Hi, Nathan!

Thanks for the reply! I tried to make this work but I couldn't! Finally 
I came up with a workaround:

I removed the velocity tools archives and went back to velocity-1.4.jar. 
I changed my servlets to subclass VelocityServlet (which is deprecated 
in the tools archive) and I used the
FileResourceManager. In the servlets I overrode the loadCongifuration() 
method and I dinamically found the path to the templates folder (this is 
the whole idea behind the webapp loader
since it does find the templates folder relative to the webapp path) 
with the getRealPath("/") method. I know this ugly, but it works. I 
would still like to know the answer to why it behaves
like I wrote before with the VelocityViewServlet.

Nathan Bubna wrote:
> On 5/2/07, Dan Nicolici <dan.nicolici@nexource.ro> wrote:
>> Hi, all!
>>
>> I'm using VelocityViewServlet in my webapp and I came across a weird
>> problem. Every time I open a new browser window and call my webapp URL,
>> the variables from my .vm are shown instead of the desired content (like
>> $varname). This only happens the on first access on a new browser
>> window. After I hit refresh in the browser everything is ok (I get the
>> desired content). Then, if I open a new instance of the browser, the
>> same thing happens all over again (the webserver is not shutdown between
>> the two actions).
>
> That's odd.  What do your servlet logs say on the first hit? (and
> perhaps on the second also)?
On the first hit it says it cannot find a velocity file needed 
(someFile.vm) which of course is written by me. On the hits that follow, 
this doesn't happen.
>
>> I am using Tomcat 5.5. The servlet is declared in the web.xml like this:
>>
>>     <servlet>
>>         <servlet-name>MyServlet</servlet-name>
>>         <servlet-class>
>>            package.UsersServlet
>>         </servlet-class>
>
> i presume this is a subclass of VelocityViewServlet?
Correct! ...my mistake for leaving it out
>
>>         <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>MyServlet</servlet-name>
>>         <url-pattern>/index.html</url-pattern>
>>     </servlet-mapping>
>>
>> velocity.properties looks like this:
>>
>> resource.loader = webapp
>> webapp.resource.loader.class =
>> org.apache.velocity.tools.view.servlet.WebappLoader
>> webapp.resource.loader.path = /templates
>> # Set cache to true for production
>> webapp.resource.loader.cache = false
>> webapp.resource.loader.modificationCheckInterval = 60
>> velocimacro.library = myMacro.vm
>>
>> Can you please help me in getting the right content from the first page
>> access? What am I doing wrong (cause I must be doing something wrong)?
>
> it's hard to tell with the information given.  you can always try
> comparing your application to the "simple" example app that comes with
> VelocityTools and see where things are different.  i can tell you that
> this is not llikely to be a problem with the resource loader.   it
> seems like either your context is not populated on first request, or
> else the template is being processed (if at all) by something besides
> your VelocityViewServlet subclass.
>
> also, what version of VelocityTools are you using? (probably not
> relevant, but i'm curious.)
Velocity tools 1.3
>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>> For additional commands, e-mail: user-help@velocity.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>
>



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


Mime
View raw message