码迷,mamicode.com
首页 > 其他好文 > 详细

FreeMarker页面中获得contextPath

时间:2014-09-01 12:09:13      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   io   使用   java   strong   

要在ftl页面中使用contextPath,需要在viewResolver中做如下配置(红色部分):

<bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
    <property name="cache" value="true" />
    <property name="prefix" value="" />
    <property name="suffix" value=".ftl" />
    <property name="exposeSpringMacroHelpers" value="true"/>
    <property name="requestContextAttribute" value="rc" />  
</bean>

这样,在页面中使用${rc.contextPath} 就可获得contextPath。注意,这里的rc对应的是org.springframework.web.servlet.support.RequestContext类的实例。

FreeMarker页面中获得contextPath

标签:style   blog   http   color   os   io   使用   java   strong   

原文地址:http://www.cnblogs.com/eastson/p/3948802.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!