views:

329

answers:

2

I'm asking this on behalf of one of my students - "Does anybody have an idea how to convert JSP Struts to Velocity Struts?"

+2  A: 

For starters, you don't have to do it all at once. That's pretty important - you should only convert pages as you have time to test them or you will get some degree of a bad result. Personally, I don't generally do this, preferring Velocity for email templating only.

You have to map the VelocityView servlet (in web.xml):

<!-- Define Velocity template compiler -->
<servlet>
  <servlet-name>velocity</servlet-name>
  <servlet-class>
    org.apache.velocity.tools.view.servlet.VelocityViewServlet
  </servlet-class>
  <init-param>
    <param-name>org.apache.velocity.toolbox</param-name>
    <param-value>/WEB-INF/toolbox.xml</param-value>
  </init-param>
  <init-param>
    <param-name>org.apache.velocity.properties</param-name>
    <param-value>/WEB-INF/velocity.properties</param-value>
  </init-param>
</servlet>

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

You will also need to create the toolbox.xml file and put in any tools you want to add and create the velocity.properties, which isn't very different from other instances of this file.

See the VelocityStruts page and for overview and the VelocityView page for how to configure the Velocity servlet.

stevedbrown
A: 

hi Stevebrown, can you give me some hint that how to integrate velocity engine with struts1 for mailing purpose

Regards, Syed