zoukankan      html  css  js  c++  java
  • freemarker Velocity获取request,session

    freemarker 获取request   和  session


    <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"></property>
    </bean>

    这样,在页面中使用${rc.contextPath} 就可获得contextPath

    还有一种简单的配置 contextPath


    <bean id="freeMarkerConfigurer" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
    	<property name="freemarkerVariables">
    		<map>
    			<entry key="base" value="#{servletContext.contextPath}" />
    		</map>
    	</property>
    </bean>


    这样直接在页面使用 ${base}  就可以获取到了


    获取Session  

      直接页面写           ${Session["这里是key"]}  可以支持.属性



    Velocity获取request   和  session


    获取request

    <!-- Velocity视图解析器 默认视图 -->
    <bean id="velocityViewResolver"
    	class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
    	<property name="contentType" value="text/html;charset=UTF-8" />
    	<property name="viewNames" value="*.html" />
    	<property name="suffix" value="" />
    	<property name="dateToolAttribute" value="date" />
    	<property name="numberToolAttribute" value="number" />
    	<property name="requestContextAttribute" value="rc" />
    	<property name="order" value="0" />
    </bean>


    这样,在页面中使用${rc.contextPath} 就可获得contextPath


    使用session

    直接  ${这里写session的key}  只不过这个如果session不存在的话会显示 key    

    感觉不是很好用


    点我去查看 freemarker Velocity 自定义标签



  • 相关阅读:
    PAT 05-树7 File Transfer
    PAT 05-树6 Path in a Heap
    PAT 10-2 删除字符串中的子串
    PAT 10-1 在字符串中查找指定字符
    PAT 10-0 说反话
    PAT 08-2 求矩阵的局部最大值
    PAT 07-3 求素数
    PAT 07-2 A+B和C
    PAT 07-0 写出这个数
    PAT 06-3 单词长度
  • 原文地址:https://www.cnblogs.com/zhousiwei/p/10625872.html
Copyright © 2011-2022 走看看