velocity的使用-配置(Maven)

本文详细介绍了如何在项目中集成Velocity视图,包括在pom.xml中添加依赖、配置velocity.properties和tools.xml文件,以及在web.xml中设置servlet,为使用Velocity模板引擎进行网页渲染提供全面指导。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文转载自:https://www.cnblogs.com/chuanqimessi/p/4691921.html

 

1.在pom.xml中添加依赖 

复制代码

 1 <dependency>
 2             <groupId>org.apache.velocity</groupId>
 3             <artifactId>velocity</artifactId>
 4             <version>1.7</version>
 5         </dependency>
 6         <dependency>
 7             <groupId>org.apache.velocity</groupId>
 8             <artifactId>velocity-tools</artifactId>
 9             <version>2.0</version>
10         </dependency>

复制代码

2.从velocity-tools-2.0.jar的org.apache.velocity.tools.view包中复制出velocity.properties和tools.xml文件

到WEB-INF目录下,修改velocity.properties:

1

2

input.encoding=UTF-8

output.encoding=UTF-8

  3.配置web.xml文件中的servlet 

 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

<servlet>

        <servlet-name>velocity</servlet-name>

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

        <init-param>

            <param-name>org.apache.velocity.properties</param-name>

            <param-value>/WEB-INF/velocity.properties</param-value>

        </init-param>

        <init-param>

            <param-name>org.apache.velocity.toolbox</param-name>

            <param-value>/WEB-INF/tools.xml</param-value>

        </init-param>

    </servlet>

<servlet-mapping>

<servlet-name>velocity</servlet-name>

    <url-pattern>*.vm</url-pattern>

</servlet-mapping>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值