<bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver" p:prefix="/" p:suffix=".ftl"> <property name="cache" value="false" /> <property name="viewClass" value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" /> <property name="contentType" value="text/html;charset=UTF-8"></property> <property name="exposeRequestAttributes" value="true" /> <property name="exposeSessionAttributes" value="true" /> <property name="exposeSpringMacroHelpers" value="true" /> <property name="requestContextAttribute" value="request"/> <property name="order" value="0"></property> </bean>
in this config, there is an properties named requestContextAttribute, we request as value, them we can get context Path through request Object.
exapmle:
<!DOCTYPE HTML>
<
html
>
<
head
>
<#assign ctx = request.contextPath />
<
meta
http-equiv
=
"Content-Type"
content
=
"text/html; charset=utf-8;NO-CACHE"
/>
<
link
rel
=
"icon"
href
=
"${ctx!}/images/JASU_Squares_ J.jpg"
/>
<
link
type
=
"text/css"
rel
=
"stylesheet"
href
=
"${ctx}/css/show_list.css"
/>
<
script
type
=
"text/javascript"
language
=
"javascript"
src
=
"${ctx}/js/jquery/jqueryui/jquery.ui.core.min.js"
></
script
>
</
head
>
<@pageOnloadJs />
<!-- 页面初始化执行的脚本 -->
<@body />
</
html
>