简体   繁体   中英

Getting java.util.Calendar.YEAR in Spring message code

<spring:message code="footer.copyriteText" arguments="NEEDS TO BE DYNAMIC" htmlEscape="false"/>

I need to replace NEEDS TO BE DYNAMIC with Calendar.getInstance().get(Calendar.YEAR) . How can I achieve this using EL?

If you don't want hardcode solution like BalusC said you can use this solution

  1. Write custom jstl tag like c:set to execute constant path and return constant value then put the constant value to Page scope. This can be done via java Reflection.

  2. Use the tag

     <lib:getConstant path='java.util.Calendar.YEAR' var='v'/> 

And

arguments='${v}`

This solution can work with all constants and you may want change constant values without changing jsp code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM