-
springMVC+velocity Unable to find resource30
applicationContext.xml<!-- 配置velocity引擎 --> <bean id="velocityConfigurer" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer"> <property name="resourceLoaderPath" value="/WEB-INF/templates/" /><!-- 模板存放的路径 --> <property name="configLocation" value="classpath:velocity.properties" /> </bean> <!-- 配置视图的显示 --> <bean id="ViewResolver" class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver"> <property name="prefix" value="/" /><!-- 视图文件的前缀,即存放的路径 --> <property name="suffix" value=".vm" /><!-- 视图文件的后缀名 --> <property name="toolboxConfigLocation" value="/WEB-INF/tools.xml" /><!--toolbox配置文件路径--> <property name="dateToolAttribute" value="date" /><!--日期函数名称--> <property name="numberToolAttribute" value="number" /><!--数字函数名称--> <property name="contentType" value="text/html;charset=UTF-8" /> <property name="exposeSpringMacroHelpers" value="true" /><!--是否使用spring对宏定义的支持--> <property name="exposeRequestAttributes" value="true" /><!--是否开放request属性--> <property name="requestContextAttribute" value="req"/><!--request属性引用名称--> <!--指定layout文件--> <property name="layoutUrl" value="layout/default.vm"/> </bean>
velocity.properties (配置了很多,只列有关路径的)input.encoding=UTF-8 output.encoding=UTF-8 file.resource.loader.description = Velocity File Resource Loader file.resource.loader.class = org.apache.velocity.runtime.resource.loader.FileResourceLoader #file.resource.loader.path = . file.resource.loader.cache = false file.resource.loader.modificationCheckInterval = 2
java类使用public class VelocityUtil { private static final String DEFAULT_CHARSET = "UTF-8"; public static String parseVm(String target, VelocityContext context) { StringWriter writer = new StringWriter(1024); if (null == context) context = new VelocityContext(); Velocity.mergeTemplate(target, DEFAULT_CHARSET, context, writer); return writer.toString(); } public static String parseVm(String target, Map<String, Object> map) { StringWriter writer = new StringWriter(1024); VelocityContext context = new VelocityContext(); if (null != map) { for (String key : map.keySet()) { context.put(key, map.get(key)); } } return parseVm(target, context); } }
使用@RequestMapping(value = "/test2.rpc", method = RequestMethod.POST) @ResponseBody public String test3(HttpServletRequest req, HttpServletResponse res) throws Exception{ try { String content = VelocityUtil.parseVm("/error.vm", new VelocityContext()); return AjaxUtils.makeJson(res, false, content); } catch (Exception e) { logger.info("---------------------" + AjaxUtils.makeExceptionJson(res, e)); return AjaxUtils.makeExceptionJson(res, e); } }
异常信息如下:
Unable to find resource '/index.vm'
我调试过,发现它使用的配置,不是我在springMVC里配置好的,而是一个初始化的配置,所以我想问一下,我如果想手动渲染一个vm,得到一段html,在springMVC里我应该怎么做呢。还是说我哪里配置有问题,麻烦讲下。
2014年8月28日 21:07
目前还没有答案
相关推荐
Spring+SpringMVC+Mybatis+Velocity+Maven整合
maven+springMVC+mybatis+velocity+mysql+junit项目框架搭建
springMVC+Velocity+iBATIS的整合小demo
maven+springmvc+spring+ibatis+velocity+mysql
J2EE开发中velocity获取项目地址,使用框架springmvc+velocity视图器,velocity配置toolboxConfigLocation使.vm文件获取项目资源地址和设置静态资源地址。 此处demo实现效果为:test.vm模板通过调用${ctx.rootPath}...
Spring+Hibernate+SpringMVC+Velocity+Maven整合
Java基于Spring+SpringMVC+MyBatis实现的学生信息管理系统源码,SSM+Vue的学生管理系统。 Java基于Spring+SpringMVC+MyBatis实现的学生信息管理系统源码,SSM+Vue的学生管理系统。 Java基于Spring+SpringMVC+...
完善的Spring+SpringMVC+Mybatis+easyUI后台管理系统(RESTful API+redis).zip 完善的Spring+SpringMVC+Mybatis+easyUI后台管理系统(RESTful API+redis).zip 完善的Spring+SpringMVC+Mybatis+easyUI后台管理系统...
SpringMVC+ibatis+velocity整合例子,虽然比较简单。可以为没有配置好的同学作为参考。
一套基于SpringMVC+velocity框架的web应用 ,基于注解,页面使用sitemesh进行包含
maven+springMVC+mybatis+velocity+mysql+junit 代码生成器
以上是springmvc+spring+hibernate整合基于eclipse,oracle开发
使用最流行的Springmvc+mybatis+velocity+easyui+jquery1.4.1架构
J2ee开源模板后台是基于 springmvc+mybatis+easyui+velocity 技术实现的一套模板后台,把一些通用的功能模板化,可以在线打包生成整站源码包括 jsp页面,为开发人员节省时间 ,生成的功能有增删改查,查询包括按列...
自己做得简易 spring+springMvc+jdbc整合,可改进内容还很多,仅仅是个demo,tomcat使用的8.0
基于maven+springmvc+redis+mybatis整合案例框架,主要实现redis的读取案例
基于SpringMVC+Spring+MyBatis+Maven项目案例 基于SpringMVC+Spring+MyBatis+Maven项目案例 基于SpringMVC+Spring+MyBatis+Maven项目案例 基于SpringMVC+Spring+MyBatis+Maven项目案例 基于SpringMVC+Spring+MyBatis...
SpringMVC+Spring+Mybatis集成开发环境SpringMVC+Spring+Mybatis集成开发环境SpringMVC+Spring+Mybatis集成开发环境SpringMVC+Spring+Mybatis集成开发环境SpringMVC+Spring+Mybatis集成开发环境SpringMVC+Spring+...
Maven整合Spring+SpringMVC+Hibernate+SpringDataJPA
图书管理系统SpringMvc+mybatis