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
    感觉不是很好用

  • 相关阅读:
    在am中定义消息集束,并在CO中验证之后抛出异常。
    在EORow或者VORow中对数据进行重复性校验
    axis2 webservice jar包使用情况(转)
    std::function以及std::bind
    Qt学习过程
    NULL和nullptr
    清空表且id为0
    C++线程互斥、同步
    warning: deleting 'void *' is undefined 错误
    Classification / Recognition
  • 原文地址:https://www.cnblogs.com/zhousiwei/p/10625737.html
Copyright © 2011-2022 走看看