spring 3+velocity tools 2.0
来源:互联网 发布:mac os 软件下载 编辑:程序博客网 时间:2024/06/05 14:38
spring 3.0.5 的org.springframework.web.servlet.view.velocity.VelocityToolboxView 类只支持1.X的velocitytools,如果想让spring支持新版本的tools,只要重写org.springframework.web.servlet.view.velocity.VelocityToolboxView这个类的createVelocityContext方法,然后在配置文件里指定使用新的viewClass。
package com.rsoft.spring.controller;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.velocity.context.Context;
import org.apache.velocity.tools.Scope;
import org.apache.velocity.tools.ToolManager;
import org.apache.velocity.tools.view.ViewToolContext;
import org.springframework.web.servlet.view.velocity.VelocityToolboxView;
public class VelocityToolbox20View extends VelocityToolboxView {
@Override
protected Context createVelocityContext(Map<String, Object> model, HttpServletRequest request,
HttpServletResponse response) throws Exception {// Create a
// ChainedContext
// instance.
ViewToolContext ctx;
ctx = new ViewToolContext(getVelocityEngine(), request, response, getServletContext());
ctx.putAll(model);
if (this.getToolboxConfigLocation() != null) {
ToolManager tm = new ToolManager();
tm.setVelocityEngine(getVelocityEngine());
tm.configure(getServletContext().getRealPath(getToolboxConfigLocation()));
if (tm.getToolboxFactory().hasTools(Scope.REQUEST)) {
ctx.addToolbox(tm.getToolboxFactory().createToolbox(Scope.REQUEST));
}
if (tm.getToolboxFactory().hasTools(Scope.APPLICATION)) {
ctx.addToolbox(tm.getToolboxFactory().createToolbox(Scope.APPLICATION));
}
if (tm.getToolboxFactory().hasTools(Scope.SESSION)) {
ctx.addToolbox(tm.getToolboxFactory().createToolbox(Scope.SESSION));
}
}
return ctx;
}
}
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.velocity.context.Context;
import org.apache.velocity.tools.Scope;
import org.apache.velocity.tools.ToolManager;
import org.apache.velocity.tools.view.ViewToolContext;
import org.springframework.web.servlet.view.velocity.VelocityToolboxView;
public class VelocityToolbox20View extends VelocityToolboxView {
@Override
protected Context createVelocityContext(Map<String, Object> model, HttpServletRequest request,
HttpServletResponse response) throws Exception {// Create a
// ChainedContext
// instance.
ViewToolContext ctx;
ctx = new ViewToolContext(getVelocityEngine(), request, response, getServletContext());
ctx.putAll(model);
if (this.getToolboxConfigLocation() != null) {
ToolManager tm = new ToolManager();
tm.setVelocityEngine(getVelocityEngine());
tm.configure(getServletContext().getRealPath(getToolboxConfigLocation()));
if (tm.getToolboxFactory().hasTools(Scope.REQUEST)) {
ctx.addToolbox(tm.getToolboxFactory().createToolbox(Scope.REQUEST));
}
if (tm.getToolboxFactory().hasTools(Scope.APPLICATION)) {
ctx.addToolbox(tm.getToolboxFactory().createToolbox(Scope.APPLICATION));
}
if (tm.getToolboxFactory().hasTools(Scope.SESSION)) {
ctx.addToolbox(tm.getToolboxFactory().createToolbox(Scope.SESSION));
}
}
return ctx;
}
}
相关视图配置
<bean id="velocityViewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
<property name="order" value="0"/>
<property name="cache" value="true" />
<property name="prefix" value="" />
<property name="suffix" value=".html" />
<property name="toolboxConfigLocation" value="/WEB-INF/tools.xml"/>
<property name="viewClass" value="com.rsoft.spring.controller.VelocityToolbox20View"/>
<property name="contentType">
<value>text/html;charset=UTF-8</value>
</property>
<property name="order" value="0"/>
<property name="cache" value="true" />
<property name="prefix" value="" />
<property name="suffix" value=".html" />
<property name="toolboxConfigLocation" value="/WEB-INF/tools.xml"/>
<property name="viewClass" value="com.rsoft.spring.controller.VelocityToolbox20View"/>
<property name="contentType">
<value>text/html;charset=UTF-8</value>
</property>
</bean>
0 0
- spring 3+velocity tools 2.0
- spring 3.0.5+velocity tools 2.0
- Spring MVC 4.0 + Velocity Tools 2.0遇到的问题
- Spring mvc 3.0 怎么配置velocity tools (dateTool/numberTool)?
- velocity-tools spring中使用toolbox的一些破事
- Velocity Tools 配置资源
- Velocity Tools例子
- Spring velocity
- Spring Velocity
- Velocity Tools 2.0 的 ResourceTool 用起来挺爽
- springboot+velocityLayout和velocity-tools
- 3、spring mvc sitemesh velocity整合
- velocity+struts+spring+ibatis
- velocity和spring整合
- Spring使用Velocity模版
- Spring PropertyPlaceholderConfigurer with Velocity
- spring-velocity-jsp
- Spring整合velocity
- 数据结构实验之栈二:一般算术表达式转换成后缀式
- iOS7 新Storyboard的使用(二)
- 阶乘运算 已测试999!
- android的常用开发包
- 句柄值可以共享,但是不能使用
- spring 3+velocity tools 2.0
- Oracle DECODE 函数应用示例
- NOSQL-Memcached
- CSS content内容生成技术以及应用
- [iOS] 推荐几个提高移动应用开发效率的第三方服务
- 任意两数制之间的转换(C++语言实现)
- 开发jQuery插件的方法
- 神经网络:卷积神经网络 http://www.cnblogs.com/ronny/p/ann_03.html
- Python之构建一个简单的web.py框架的服务器