简体   繁体   中英

How do you list every letter from a-z in jstl

Using jstl I want to list each letter of the alphabet.

I want something like ab ... z

<c:set var="alphabet" value="A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z" />
<c:forTokens var="letter" items="${alphabet}" delims=",">
    ${letter}
</c:forTokens>

Ok, no scriptlet. How about a JSP expression? If you don't want either of them, then you can create a custom EL function. Look near bottom of Hidden features of JSP/Servlet

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>  
<c:forEach var="i" begin="97" end="122">
    <%=Character.toChars((Integer)pageContext.getAttribute("i"))%>
</c:forEach>

Assuming you can inject java directly in (I don't know JSTL) you could do this

for(char letter = 'a'; letter <= 'z'; letter++) {
    System.out.println(letter + " ");
}

keeping in mind that a char is just an unsigned integer.

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