首页 > 代码库 > Freemarker中通过request获得contextPath

Freemarker中通过request获得contextPath

<!-- config Freemarker View Resolver-->
       <bean id="viewResolver"  
         class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
            <property name="viewClass" value="http://www.mamicode.com/org.springframework.web.servlet.view.freemarker.FreeMarkerView"/>  
         <property name="contentType" value="http://www.mamicode.com/text/html;charset=utf-8"/>
         <property name="cache" value="http://www.mamicode.com/true"/>
         <property name="suffix" value="http://www.mamicode.com/.ftl"/>  
         <property name="order" value="http://www.mamicode.com/0"/>  
         <property name="requestContextAttribute" value="http://www.mamicode.com/request"/>
       </bean> 

    2. 在ftl文件中使用request

  <#assign ctx=request.getContextPath()>

Freemarker中通过request获得contextPath