velocity 中使用<c:import/>

<c:import/>是jsp里面的东西,在velocity里面当然不能用,不过velocity有自己的插件,叫做ImportTool。

 

ImportTool的使用:

原文地址:http://velocity.apache.org/tools/devel/view/ImportTool.html

 

以下是引用:

 

ImportTool Reference Documentation

General-purpose text-importing view tool for templates.

Class
 org.apache.velocity.tools.view.tools.ImportTool
Name
 $import (this is the recommended name of the tool in the Velocity context)
Toolbox Configuration Example
 
<tool>
  <key>import</key>
  <scope>request</scope>
  <class>org.apache.velocity.tools.view.tools.ImportTool</class>
</tool>
Author(s)
 Marino A. Jonsson
Method Overview
read() Returns the supplied URL rendered as a String.

read()

Returns the supplied URL rendered as a String.

String read(String url)

Parameters
url
The URL to import.
Returns
The supplied URL rendered as a String.

This method takes an arbitrary URL or URI and renders it as a String. This tool can also be used to import local .vm resources without sharing the current velocity-context (as opposed to the #parse directive).

$import.read("http://velocity.apache.org/tools/devel/")
$import.read("/wookie.jsp")

 

 

 

velocity tools的安装请看:

原文地址:http://velocity.apache.org/tools/devel/view/index.html#Installation

 

以下是引用:

 

The servlet configuration (web.xml ) must be modified to include a reference to the VelocityViewServlet (or subclass thereof) which will perform the rendering. All *.vm files are mapped to this servlet which will populate the 'context' with Request, Session, and Application scopes plus any additional tools specified in the toolbox.xml file. The servlet will use this contextual information and the Velocity Engine to render the template file.

 

Note: Additional functionality can be achieved through subclassing the VelocityViewServlet, and will be discussed further in the VelocityLayoutServlet below.

web.xml

<!-- Define Velocity template compiler -->
<servlet>
  <servlet-name>velocity</servlet-name>
  <servlet-class>
    org.apache.velocity.tools.view.servlet.VelocityViewServlet
  </servlet-class>

  <!-- 
    Unless you plan to put your toolbox.xml and velocity.properties
    under different folders or give them different names, then these
    two init-params are unnecessary as of VelocityTools 1.3.  The
    VelocityViewServlet will automatically look for these files in
    the following locations.
  -->
  <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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值