On 8/1/07, Nathan Bubna <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]