Nested expression in JSP/JSTL

后端 未结 1 487
半阙折子戏
半阙折子戏 2021-01-05 05:24

I am using JSPs for the view, and Spring MVC 3.0 for the controller. In my JSP, I want to show the current DateTime, for which I have the following code...

&         


        
相关标签:
1条回答
  • 2021-01-05 05:45

    <c:set> can take its value from the tag content, instead of from the value attribute:

    <c:set var="dateTimeDisplayFormat">
        <spring:message code="display.dateFormat" />
    </c:set>
    
    <c:set var="currentDateTime" scope="page">
        <%= new SimpleDateFormat(${dateTimeDisplayFormat}).format(new Date()) %>
    </c:set>    
    

    Better yet, you shouldn't need <c:set> at all, since both <spring:message> and <fmt:formatDate> can store their results in variables for you:

    <spring:message code="display.dateFormat" var="dateTimeDisplayFormat"/>
    <fmt:formatDate pattern="${dateTimeDisplayFormat}" var="currentDateTime" scope="page"/>
    
    0 讨论(0)
提交回复
热议问题