JSTL padding int with leading zeros

I am trying to use JSTL to create a form. I have a choice for months, but I need months to always be two digits, that is, filled on the left with a zero value for 1-9.

I have this, but it is obvious that he does not give me what I want.

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    <select class="formInput">
        <c:forEach var="i" begin="1" end="12" step="1" varStatus ="status">
            <option><fmt:formatNumber pattern="##" value="${i}" /></option>
        </c:forEach>
    </select>

This should have been done before, but I can’t find an example after a short search.

+5
source share
1 answer

found the answer: minIntegerDigits

<select class="formInput">
    <c:forEach var="i" begin="1" end="12" step="1" varStatus ="status">
        <option><fmt:formatNumber minIntegerDigits="2" value="${i}" /></option>
    </c:forEach>
</select>
+12
source

All Articles