velocity的配置

1.将VelocityWebEdit-1.0.8文件夹下的plugins子文件加拷贝到eclipse的根目录下
2.将jars文件夹下所有jar文件复制到项目web-info的lib文件夹中
3.创建Velocity.properties文件,内容参见TestVeclocity项目

文件内容为以下
velocimacro.permissions.allow.inline=true
input.encoding = gbk
output.encoding = UTF-8
default.contentType=text/html; charset=utf-8

4.在web.xml中添加
<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>
    <load-on-startup>10</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>velocity</servlet-name>
    <url-pattern>*.vm</url-pattern>
  </servlet-mapping>


5创建toolbox.xml 基于struts开发的

<?xml version="1.0"?>
<toolbox>
<tool>
<key>link</key>
<scope>request</scope>
<class>org.apache.velocity.tools.struts.StrutsLinkTool</class>
</tool>
<tool>
<key>msg</key>
<scope>request</scope>
<class>org.apache.velocity.tools.struts.MessageTool</class>
</tool>
<tool>
<key>errors</key>
<scope>request</scope>
<class>org.apache.velocity.tools.struts.ErrorsTool</class>
</tool>
<tool>
<key>form</key>
<scope>request</scope>
<class>org.apache.velocity.tools.struts.FormTool</class>
</tool>
<tool>
<key>tiles</key>
<scope>request</scope>
<class>org.apache.velocity.tools.struts.TilesTool</class>
</tool>
<tool>
<key>validator</key>
<scope>request</scope>
<class>org.apache.velocity.tools.struts.ValidatorTool</class>
</tool>
</toolbox>

6 文件头
<html>
  <head>
    <title>MyHtml.html</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
 
  <body>
  </body>
  </html>

你可能感兴趣的:(apache,Web,xml,struts,velocity)