velocity 에서 사용

3753 단어 C++cservletvelocityC#
< 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>

좋은 웹페이지 즐겨찾기