You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Christopher Townson <ch...@christophertownson.com> on 2007/08/01 11:40:39 UTC

Re: How to configure VelocityServlet to answer specific context?

>> On 8/1/07, Nathan Bubna <nb...@gmail.com> wrote: Change the
>> url-pattern under the servlet-mapping for the velocity servlet to
>> "/velocity/*" instead of "*.vm"
>> 
> Joe Kramer wrote: That doesn't help, I still get velocity template on
> any URL, and navigating to /velocity/ produces Exception: 
> org.apache.velocity.exception.ResourceNotFoundException: Unable to 
> find resource '/velocity/'
> 

Hi Joe,

The Velocity View Servlet calls getServletPath() and getPathInfo() on 
the request to obtain path information for the current template, which 
is then passed to a resource loader.

i.e.

a request "GET /index.html" to a VVS mapped to "*.html" will result in 
the path "/index.html" being passed to the resource loader

a request "GET /" to a VVS mapped to "*.html" will result in the path 
"/[welcome-file-name.html]" being passed to the resource loader (if 
welcome-file is configured to be a .html file), but _only_ because the 
servlet container will insert the welcome file name for you.

if you map in web.xml to "/whatever/*", everything after "/whatever/" 
will be treated as path info, and the servlet container will not 
interfere by appending welcome file names etc to ambiguous requests.

Therefore, a request for "GET /velocity/" to a VVS mapped to 
"/velocity/*" will result an unresolveable path being supplied to the 
resource loader (either empty string, "/", or null - can't remember 
which) ... which will cause the ResourceNotFoundException.

The problem can be worked around by implementing a simple 
"PathInfoResourceLoader" which looks for ambiguous template paths (e.g. 
"/") then picks up the configured welcome-file(s) from the context and 
appends them as necessary in order to resolve the request to a template.

... as for the other problem with velocity templates being picked up on 
any requests, even when the VVS is mapped to "/velocity/*" - well, I 
simply do not see how that could happen! Are you sure that is the case?

Chris


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


Re: How to configure VelocityServlet to answer specific context?

Posted by Nathan Bubna <nb...@gmail.com>.
You sense wrong.  We do it all the time at my company.  It works much
like the standard JspServlet or the FreemarkerServlet or most any
other view-layer servlet or filter out there.  Moving it to a
different webapp won't make the servlet engine handle welcome files
differently.  This is a servlet engine/web.xml configuration issue.
There's something screwy with your web.xml or servlet engine in
general if you are getting calls to the VVS for requests that don't
match the url-pattern set for the VVS.  The VVS doesn't decide what
requests the servlet engine decides to pass to it.  It just handles
them as best it can.  This is not an issue with the VVS.

On 8/1/07, Joe Kramer <cc...@gmail.com> wrote:
> Thanks,
>
> I guess the right and logical way will be to move VelocityViewServlet
> into separate webapp. I sense it wasn't designed to coexist with other
> contexts in same webapp.
>
> On 8/1/07, Christopher Townson <ch...@christophertownson.com> wrote:
> > >> On 8/1/07, Nathan Bubna <nb...@gmail.com> wrote: Change the
> > >> url-pattern under the servlet-mapping for the velocity servlet to
> > >> "/velocity/*" instead of "*.vm"
> > >>
> > > Joe Kramer wrote: That doesn't help, I still get velocity template on
> > > any URL, and navigating to /velocity/ produces Exception:
> > > org.apache.velocity.exception.ResourceNotFoundException: Unable to
> > > find resource '/velocity/'
> > >
> >
> > Hi Joe,
> >
> > The Velocity View Servlet calls getServletPath() and getPathInfo() on
> > the request to obtain path information for the current template, which
> > is then passed to a resource loader.
> >
> > i.e.
> >
> > a request "GET /index.html" to a VVS mapped to "*.html" will result in
> > the path "/index.html" being passed to the resource loader
> >
> > a request "GET /" to a VVS mapped to "*.html" will result in the path
> > "/[welcome-file-name.html]" being passed to the resource loader (if
> > welcome-file is configured to be a .html file), but _only_ because the
> > servlet container will insert the welcome file name for you.
> >
> > if you map in web.xml to "/whatever/*", everything after "/whatever/"
> > will be treated as path info, and the servlet container will not
> > interfere by appending welcome file names etc to ambiguous requests.
> >
> > Therefore, a request for "GET /velocity/" to a VVS mapped to
> > "/velocity/*" will result an unresolveable path being supplied to the
> > resource loader (either empty string, "/", or null - can't remember
> > which) ... which will cause the ResourceNotFoundException.
> >
> > The problem can be worked around by implementing a simple
> > "PathInfoResourceLoader" which looks for ambiguous template paths (e.g.
> > "/") then picks up the configured welcome-file(s) from the context and
> > appends them as necessary in order to resolve the request to a template.
> >
> > ... as for the other problem with velocity templates being picked up on
> > any requests, even when the VVS is mapped to "/velocity/*" - well, I
> > simply do not see how that could happen! Are you sure that is the case?
> >
> > Chris
> >
> >
> > ---------------------------------------------------------------------
> > 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


Re: How to configure VelocityServlet to answer specific context?

Posted by Joe Kramer <cc...@gmail.com>.
Thanks,

I guess the right and logical way will be to move VelocityViewServlet
into separate webapp. I sense it wasn't designed to coexist with other
contexts in same webapp.

On 8/1/07, Christopher Townson <ch...@christophertownson.com> wrote:
> >> On 8/1/07, Nathan Bubna <nb...@gmail.com> wrote: Change the
> >> url-pattern under the servlet-mapping for the velocity servlet to
> >> "/velocity/*" instead of "*.vm"
> >>
> > Joe Kramer wrote: That doesn't help, I still get velocity template on
> > any URL, and navigating to /velocity/ produces Exception:
> > org.apache.velocity.exception.ResourceNotFoundException: Unable to
> > find resource '/velocity/'
> >
>
> Hi Joe,
>
> The Velocity View Servlet calls getServletPath() and getPathInfo() on
> the request to obtain path information for the current template, which
> is then passed to a resource loader.
>
> i.e.
>
> a request "GET /index.html" to a VVS mapped to "*.html" will result in
> the path "/index.html" being passed to the resource loader
>
> a request "GET /" to a VVS mapped to "*.html" will result in the path
> "/[welcome-file-name.html]" being passed to the resource loader (if
> welcome-file is configured to be a .html file), but _only_ because the
> servlet container will insert the welcome file name for you.
>
> if you map in web.xml to "/whatever/*", everything after "/whatever/"
> will be treated as path info, and the servlet container will not
> interfere by appending welcome file names etc to ambiguous requests.
>
> Therefore, a request for "GET /velocity/" to a VVS mapped to
> "/velocity/*" will result an unresolveable path being supplied to the
> resource loader (either empty string, "/", or null - can't remember
> which) ... which will cause the ResourceNotFoundException.
>
> The problem can be worked around by implementing a simple
> "PathInfoResourceLoader" which looks for ambiguous template paths (e.g.
> "/") then picks up the configured welcome-file(s) from the context and
> appends them as necessary in order to resolve the request to a template.
>
> ... as for the other problem with velocity templates being picked up on
> any requests, even when the VVS is mapped to "/velocity/*" - well, I
> simply do not see how that could happen! Are you sure that is the case?
>
> Chris
>
>
> ---------------------------------------------------------------------
> 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