需要lib
velocity-1.4.jar,
velocity-tools-1.2.jar
copy to /WEB-INF/lib目录下
修改web.xml
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
</servlet>
<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/properties/velocity.properties</param-value>
</init-param>
</servlet>
<!-- Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>velocity</servlet-name>
<url-pattern>*.vm</url-pattern>
</servlet-mapping>
加了红色部分。
新建velocity属性文件(velocity.properties),内容如下
# the following are specified relative to the
# root of the webapp because the
# ControllerServlet will setup these
# properties with the right real path
# prepended
#
file.resource.loader.path=/vm
runtime.log=${bluetop.root}/logs/velocity.log
#encodeing
input.encoding = GBK
output.encoding = GBK
写一test class文件
public class VelocityTest extends BaseAction {
/* (non-Javadoc)
* @see com.bluetop.web.action.BaseAction#executeAction(org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public String executeAction(ActionForm actionFrom,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
List<String> list = new ArrayList<String>();
list.add("velocity测试");
list.add("velocity测试 element 2");
list.add("velocity测试 element 3");
list.add("velocity测试 element 4");
request.setAttribute("list", list);
return "example";
}
}
配置struts-config.xml
<action path="/vtest" scope="request" type="com.bluetop.demo.VelocityTest">
<forward name="example" path="/vm/example.vm"/>
</action>
新建example.vm
## This is an example velocity template
#set( $this = "Velocity")
$this is great!
#foreach( $name in $list )
$name is great!
#end
#set( $condition = true)
#if ($condition)
The condition is true!
#else
The condition is false!
#end
执行/vtest.do输出内容如下:
Velocity is great! velocity测试 is great! velocity测试 element 2 is great! velocity测试 element 3 is great! velocity测试 element 4 is great! The condition is true!
Velocity工作正常,over
相关推荐
一个很简单容易上手的struts2与velocity集成 实例;很方便初学者进入struts2与velocity集成 学习
Struts2集成FreeMarker和Velocity,写成了工具类,快速实现页面静态化,以后直接调用即可,无需修改任何源代码,改压缩文件包括 1、工具类; 2、源码(含jar包); 3、mysql数据库可执行文件; 4、struts2集成...
他也可用于一个独立的程序以产生源代码和报告,或者作为其它系统的一个集成组件。这个项目完成后,Velocity将为Turbine web 应用程序框架提供模板服务。Velocity+Turbine 方案提供的模板服务将允许web 应用按真正的...
这段时间学习mongo数据库,花点时间搭了个框架,资源是myeclipse10整个工程包,有问题随便问。
文章对应代码 博文链接:https://aideqianfang.iteye.com/blog/243021
struts2.2+velocity+tiles+spring3+mybatis3.05集成框架实例 ,最新的框架组合.。
集成了struts2,spring2,hibernate3,以及velocity和sittemesh的项目源代码,有兴趣的可以下载下,关键是集成velocity有点难度,呵呵.
花了所有CSDN积分收集来的Velocity资料集合: Velocity Java开发指南中文版 Velocity Web应用开发指南中文版 Velocity模板使用指南中文版 ...Struts与Velocity的简单集成 使用Velocity开发web程序
velocity相关的eclipse插件、jar包和文档。 eclipse插件:com.googlecode.veloeclipse.ui_2.0.8...jar包:velocity-1.7、velocity-tools-2.0(含有源码) 文档:velocity语法、使用以及和struts2、spring、ibatis的整合
Action执行完毕以后,可以有多种结果类型——包括渲染JSP页面,Velocity和Freemarker模板,但并不仅限于这些。最后,依赖注入也成了Struts2王国中的一等公民,这项功能是通过Spring框架的插件和Plexus共同提供的,与...
8.3.1 VelocityResult,也叫做velocity 189 8.3.2 FreemarkerResult,也叫做freemarker 191 8.4 全局结果 192 8.5 小结 193 第四部分 完善应用程序 第9章 集成Spring和Hibernate/JPA 196 9.1 为什么在Struts 2中...
Struts 2标签现在可与FreeMarker、Velocity及类似模板引擎配合使用。 · 引入拦截器: Struts 2为拦截器(interceptor)提供了全面支持。拦截器可在Action类执行前后加以执行。拦截器经配置后,可以把工作流程或者...
你也可以将Struts 组件集成到你的框架中,就 像他们是你自己编写的一样。详细情况, 参见Apache Software License , www.apache.org/LICENSE。 1.1.2. 为什么Struts 要开源? 现在有许多非常优秀Java 程序和框架都是...
JSTL(JSP Standard Tag Library),JSP 2.0集成的标准的表达式语言; Groovy,基于Java平台的动态语言,它具有时下比较流行的动态语言(如Python、Ruby和Smarttalk等)的一些起特性; Velocity,严格来说不是...
JSTL(JSP Standard Tag Library),JSP 2.0集成的标准的表达式语言; OGNL(Object-Graph Navigation Language),可以方便地操作对象属性的开源表达式语言; Velocity,严格来说不是表达式语言,它是一种基于...
Demo4SSIV 教学用的集成Struts、Spring、iBatis、Velocity的示例代码。通过6天的时间,让具有Java基础的同学掌握这些技术。同时在这6天内,能以5人一组的方式,完成一个Cart项目的开发。
iBatis,JPA)、视图(JSP,JSTL,Title,Velocity,FreeMarker,XSLT,PDF/Excel文档视图、JasperReports报表视图)、Web框架(JSF、Struts、Tapestry、WebWork)其他技术(WebServices、EJB、JMS、JMX、JCA等)的集成。...
尽管这些技术在国外都已进很流行了,但在国内能够将Hibernate、 Struts、Spring、DBUnit、Ant、Log4J、Struts Menu、Xdoclet、SiteMesh、Velocity、JUnit、JSTL、WebWork这些技术集成到一个框架中的还不多见,所以...
Tags are one of the things that make Struts unique compared to other frameworks like Velocity. Note: "Think thin" when extending the Action class. The Action class should control the flow and not ...