JSTL <c:set> body content exact specification

本秂侑毒 提交于 2019-12-20 02:27:09

问题


can someone suggest how possible to interpret <c:set> body?

  • <c:set var="movieList">One,Two,Three</c:set>

  • <c:set var="movieList">"One","Two","Three"</c:set>

in the first case movieList is a string and in the second it is an array {"One", "Two", "Three"}

what is movieList in these examples:

  • <c:set var="movieList">"On"e","Tw"o","Thr"ee"</c:set>

  • <c:set var="movieList">"On\"e","Tw"o","Thr\"ee"</c:set>


回答1:


There's no difference in the interpreted Java type of the c:set's body. It are in all cases just String.

Even when you set a non-String type as c:set's body using EL such as

<c:set var="foo">${bean.someInteger}</c:set>

it'll be converted to String anyway by String#valueOf().

Only when you process the variable afterwards, there may be difference, depending on how you processed it. For example,

<c:set var="movieList">One,Two,Three</c:set>
<c:set var="realMovieArray" value="${fn:split(movieList, ',')}" />

will result ${realMovieArray} being a String[] with values of One, Two and Three.




回答2:


<c:set var="alphabet">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:set>

<c:forTokens items="${alphabet}" delims="," var="letter">
    ${letter}
</c:forTokens>


来源:https://stackoverflow.com/questions/6820666/jstl-cset-body-content-exact-specification

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!