freemarker rem

86334592 2013-08-25

1. 获取cookie.
   <#assign cookies = request.getCookies()>
       <#list cookies as cookie>
             <#if cookie.name = "userName">
                   ${cookie.name}
                   ${cookie.value}
               </#if>
      </#list>

2. 获取request.
<#if Request["shoppingCart"]?exists>
<#assign shoppingCart = Request["shoppingCart"]>

3.session.
<#if Session["shoppingCart"]?exists>
<#assign shoppingCart = Session["shoppingCart"]>
action中:
HttpServletRequest request = ServletActionContext.getRequest();
    request.getSession().setAttribute("pathtu", filepath);
ftl页面:
${Session["pathtu"]?default("Session")}
读取堆栈:
<#assign code=((stack.findString("#parameters['code']"))?default('001'))/>

在后台给request,session设置值即可在ftl页面使用的,如:

public ModelAndView employeeItemKpi(HttpServletRequest request,String employeeName) {

    request.setAttribute("name", "your value");

    HttpSession session = request.getSession();
    session.setAttribute("isAll", isAll);

}

相关推荐

LetonLIU / 0评论 2020-05-29