Question

So after installing UrlRewriteFilter, I set up a rule and a corresponding velocity template. And when I go to the test page, the velocity script is shown as raw code instead of being compiled.

example of the code for the rule:

<rule>
   <from>/test/([0-9]+)</from>
   <to>/downloads/test.vm?Id=$1</to>
</rule>

example of the urlrewritefilter

<filter>
   <filter-name>UrlRewriteFilter</filter-name>
   <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
    <init-param>
        <param-name>logLevel</param-name>
        <param-value>DEBUG</param-value>
    </init-param>
</filter>

any ideas why the velocity template wouldn't render even though the rule executed correctly? All other vm pages render correctly (when accessed directly) and the rewrite works perfectly with jsp.

Was it helpful?

Solution

This happens when the test.vm is served by the default servlet for static content.

I suspect you changed the mapping for velocity somehow. If you are using Velocity Tools, you should have a mapping like this,

<servlet>
  <servlet-name>velocity</servlet-name>
  <servlet-class>
    org.apache.velocity.tools.view.VelocityViewServlet
  </servlet-class>
</servlet>

<!-- Map all *.vm files to Velocity -->
<servlet-mapping>
  <servlet-name>velocity</servlet-name>
  <url-pattern>*.vm</url-pattern>
</servlet-mapping>

Another possibility is that other filter might interfere with UrlRewrite filter. It would be helpful if you can post your web.xml.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top