Spring MVC完成指南(五)Velocity
2009-03-27 09:36
295 查看
继上一篇完成buffalo的整合后,Spring MVC的显现层可以用Velocity来表现。Velocity是很简单实用的模板引擎。根据上一篇的信息,我会继续更新代码。
Spring中包含了velocity的包,但是需要另外两个包的支持才能正常调用。
spring-support.jar 和commons-collections-3.1.jar
如果没有这两个包,执行调用的时候一直会出错。我为此也找了2天的资料,后来才发现是缺少包.......
项目图:
主要修改的地方如下:
velocity.properties
dispatcherServlet.xm
完成修改后,装载webapp就可以看到运行结果。
下一篇会是关于webflow的集成和使用,待续......
Spring中包含了velocity的包,但是需要另外两个包的支持才能正常调用。
spring-support.jar 和commons-collections-3.1.jar
如果没有这两个包,执行调用的时候一直会出错。我为此也找了2天的资料,后来才发现是缺少包.......
项目图:
主要修改的地方如下:
velocity.properties
resource.loader=class class.resource.loader.class=org.apache.Velocity.runtime.resource.loader.ClasspathResourceLoader file.resource.loader.cache=false input.encoding = UTF-8 output.encoding = UTF-8
dispatcherServlet.xm
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <!-- This bean sets up the Velocity environment for us based on a root path for templates. Optionally, a properties file can be specified for more control over the Velocity environment, but the defaults are pretty sane for file based template loading. --> <bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer"> <property name="resourceLoaderPath" value="/" /> </bean> <!-- View resolvers can also be configured with ResourceBundles or XML files. If you need different view resolving based on Locale, you have to use the resource bundle resolver. --> <bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver"> <property name="contentType"><value>text/html;charset=UTF-8</value></property> <property name="cache" value="true"/> <property name="prefix" value="/jsp/"/> <property name="suffix" value=".jsp"/> </bean> <!-- 定义视图及路径 <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass"> <value>org.springframework.web.servlet.view.JstlView</value> </property> --> <!-- JSP都放在WEB-INF/jsp目录下 <property name="prefix"> <value>/jsp/</value> </property> --> <!-- JSP页面的后缀都四.JSP <property name="suffix"> <value>.jsp</value> </property> </bean> --> <!-- 定义映射 --> <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <prop key="/action.do">action</prop> </props> </property> </bean> <!-- 定义控制器 --> <bean id="action" class="cn.Action"> <property name="commandClass"> <value>cn.Person</value> </property> <!-- 指定验证类 <property name="validator"> <ref bean="userValidator"/> </property> --> <!-- 指定失败要返回的页面 --> <property name="success_View"> <value>test</value> </property> </bean> <!-- 定义验证类 <bean id="userValidator" class="cn.UserValidator"></bean> --> </beans>
完成修改后,装载webapp就可以看到运行结果。
下一篇会是关于webflow的集成和使用,待续......
相关文章推荐
- Spring MVC完成指南(三)国际化的支持:Spring MVC Velocity
- Spring MVC完成指南(三)国际化的支持:Spring MVC Velocity
- Spring MVC完成指南(三)国际化的支持:Spring MVC Velocity
- Spring MVC完成指南(一)Spring MVC
- Spring MVC完成指南(四)Ajax buffalo
- Spring MVC完成指南(二)Hibernate :SchemaExportTask 类的生成
- Spring MVC完成指南(二)Hibernate
- Spring MVC完成指南(三)国际化的支持
- Spring MVC完成指南(一)Spring MVC MultiActionController
- Spring MVC整合Velocity
- Spring MVC整合Velocity详解
- 【笔记】Spring MVC学习指南(八)表达式语言
- 【笔记】Spring MVC学习指南(十)国际化
- 【笔记】Spring MVC学习指南(附录)
- Velocity的中文指南(1)
- Spring MVC 入门指南(一):HelloWorld
- Spring MVC 入门指南(二):@RequestMapping用法详解
- spring mvc velocity中文问题
- spring mvc整合velocity源码分析
- Spring MVC学习指南(8-10章总结)