要在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类的实例。

相关文章:

  • 2021-08-02
  • 2021-07-02
  • 2021-12-14
  • 2022-12-23
  • 2022-12-23
  • 2021-09-17
  • 2021-08-28
猜你喜欢
  • 2022-12-23
  • 2021-11-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-21
  • 2022-12-23
相关资源
相似解决方案