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

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

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

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

最新文章

  1. BZOJ 1717: [Usaco2006 Dec]Milk Patterns 产奶的模式 [后缀数组]
  2. react-native-http请求后navigator导航跳转
  3. oracle判断字段是否存在语句
  4. 360极速浏览器安装.crx扩展(postman)
  5. [代码片段]OSTU算法
  6. P3384: [Usaco2004 Nov]Apple Catching 接苹果
  7. URL伪静态设置 (apache2.4)
  8. NYOJ 58 步数最少 【BFS】
  9. c++内存流
  10. 阿里云正式上线移动直播问答解决方案,助力APP尽情“撒币”!
  11. JAVA进阶18
  12. messageQ 消息队列
  13. whil
  14. rabbitmq系统学习(一)
  15. Nginx安装及配置详解【转】
  16. ubuntu输入法
  17. 英文写作指南——《“compare to”等同“compare with”吗?》
  18. DIM-00014: Cannot open the Windows NT Service Control Manager.
  19. Python中sorted()方法的用法
  20. 为什么子元素设置margin-top会作用在父元素上?

热门文章

  1. Centos7从3.10升级内核到4.9后无法启动解决办法:mpt[23]sas驱动问题
  2. SYN 和 RTO
  3. 洛谷P1307 数字反转【水题】
  4. JavaEE el表达式中三目运算符的使用
  5. 1. 构建第一个SpringBoot工程
  6. python数据标准化
  7. git常见问题总结
  8. 通用 mapper
  9. 0818基于360开源数据库流量审计MySQL Sniffer
  10. [bzoj1180][CROATIAN2009]OTOCI_LCT