转载:http://blog.csdn.net/whatlookingfor/article/details/51538995

在SpringMVC框架中使用Freemarker试图时,要获取根路径的方式如下:

  1. <!-- FreeMarker视图解析 如返回userinfo。。在这里配置后缀名ftl和视图解析器。。 -->
  1. <bean id="viewResolverFtl"
  2. class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
  3. <property name="viewClass"
  4. value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" />
  5. <property name="suffix" value=".ftl" />
  6. <property name="contentType" value="text/html;charset=UTF-8" />
  7. <property name="exposeRequestAttributes" value="true" />
  8. <property name="exposeSessionAttributes" value="true" />
  9. <property name="exposeSpringMacroHelpers" value="true" />
  10. <property name="requestContextAttribute" value="request" />
  11. <property name="cache" value="true" />
  12. <property name="order" value="0" />
  13. </bean>

其中property name=”requestContextAttribute” value=”request”是关键。 
意思是把Spring的RequestContext对象暴露为变量request 
利用${request.contextPath}来获取应用程序的contextPath

项目随笔之springmvc中freemark如何获取项目路径的更多相关文章

  1. springMvc中restful风格的api路径中把小数点当参数,SpringMvc中url有小数点

    在springMvc web项目中restful风格的api路径中有小数点会被过滤后台拿不到最后一个小数点的问题, 有两种解决方案: 1:在api路径中加入:.+ @RequestMapping(&q ...

  2. Android无法导入下载好的项目(和Eclipse中已经存在的项目命名一样导致冲突)解决办法

    错误提示: 在我们到导入从网络下载的项目时,经常会出现如下问题(选择的项目变灰,并且提示要选择至少一个项目): 错误原因: 出现这样的错误主要是因为你的Eclipse已经存在了和上图中New Proj ...

  3. java(JSP)中几种获取项目路径方式

    在jsp和class文件中调用的相对路径不同. 在jsp里,根目录是WebRoot 在class文件中,根目录是WebRoot/WEB-INF/classes 当然你也可以用System.getPro ...

  4. 161018、springMVC中普通类获取注解service方法

    1.新建一个类SpringBeanFactoryUtils 实现 ApplicationContextAware package com.loiot.baqi.utils; import org.sp ...

  5. java中几种获取项目路径方式

    转自http://caodaoxi.iteye.com/blog/1234805     在jsp和class文件中调用的相对路径不同. 在jsp里,根目录是WebRoot 在class文件中,根目录 ...

  6. 在springmvc中使用requestContextListener获取全部的request对象

    RequestContextListener实现了 ServletRequestListener ,在其覆盖的requestInitialized(ServletRequestEvent reques ...

  7. springMVC 中几种获取request和response的方式

    1.最简单方式:参数 例如: @RequestMapping("/test") @ResponseBody public void saveTest(HttpServletRequ ...

  8. java web项目导入到eclipse中变成了java项目的一种情况的解决办法

    前提,我把代码上传到github上之后,在另外一台电脑上拉下之后,先报出现的是jre不对,然后换成了当前的jre,然后红色的感叹号消失了但是之前项目上那个小地球不见了,也就是说变成了java项目. - ...

  9. myeclipse中的web项目导入到eclipse中注意事项,项目部署到tomcat后无法访问jsp文件

    打开eclipse,点击空白处,右键可以看到import>general>existing projects into workspace>next>选择你的myeclipse ...

随机推荐

  1. Codeforces Round #548 (Div. 2) B. Chocolates

    You went to the store, selling 

  2. SQL第三节课

    常用函数 一.数学函数 数学函数主要用于处理数字,包括整型.浮点数等. ABS(x) 返回x的绝对值 SELECT ABS(-1) -- 返回1 CEIL(x),CEILING(x) 返回大于或等于x ...

  3. Parsing error: The keyword 'export' is reserved && error Parsing error: Unexpected token <

    如果你也在使用eslint,也报了如上错误,可以尝试: $ npm install babel-eslint --save-dev 然后,加上: rules: { "parser" ...

  4. 爬虫系列(六) 用urllib和re爬取百度贴吧

    这篇文章我们将使用 urllib 和 re 模块爬取百度贴吧,并使用三种文件格式存储数据,下面先贴上最终的效果图 1.网页分析 (1)准备工作 首先我们使用 Chrome 浏览器打开 百度贴吧,在输入 ...

  5. 解决HTML select控件 设置属性 disabled 后无法向后台传值的方法

    大家都知道有时候修改数据的时候我们希望有一些数据是不可以修改的,通常情况下我们会将input框设置为 readonly , 但是 select 控件没有这个属性,需要使用另一个属性 disabled ...

  6. laravel5 文件上传

    <!DOCTYPE html><html lang="zh-CN"><head> {{--设置字符编码--}} <meta charset ...

  7. codevs——T1267 老鼠的旅行

    http://codevs.cn/problem/1267/  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描述 Descr ...

  8. mybatis mapper xml文件配置resultmap时,id行和result行有什么区别?

    mybatis mapper xml文件配置resultmap时,id行和result行有什么区别? <resultMap id = "CashInvoiceMap" typ ...

  9. [React] Forward a DOM reference to another Component using forwardRef in React 16.3

    The function forwardRef allows us to extract a ref and pass it to its descendants. This is a powerfu ...

  10. 从OTF字体文件里查找字体名称

    for in ? 使用神器vim就好了. . . vim ./AKZIDENZGROTESK-COND.OTF