I don't understand the reason for the question. The expression language will automatically coerce a string to an integer if it's necessary to do so. You don't have to do anything to make that happen. Here's a reference I found with google keywords "jstl convert string to int".
Are you having a specific problem where this doesn't work, or have you not tried it yet because you thought you had to do something?
maya brown
Ranch Hand
Joined: Feb 18, 2009
Posts: 42
posted
0
oh my gosh, I was hoping my question wouldn't sound too stupid.. what it is is that I'm learning JSTL, and I'm trying to convert all scriptlets in one webapp to JSTL as a learning exercise.. I'm so used to doing back-end with scriptlets, it's a big change... so JSTL will "automatically coerce a string to an integer if it's necessary to do so"?? hmm.... if it's "necessary to do so"?? how does JSTL know if I need to convert a string to an integer?? :~) I saw the url you mention, I probably have seen all JSTL-related pages by now...;~)
here's a conditional I put together yesterday, but it's not working too well...
<!-- example url: ....jsp?pn=9 -- or it might not include the param at all -->
<c:set var='phNo' value='${param.pn}' /> <!-- comes in as string, I assume.. -->
<c:choose>
<c:when test="${phNo == null}">
<c:set var="iPhNo" value="${1}" /> <!-- correct constr for int? -->
</c:when>
<ctherwise>
<c:set var="iPhNo" value='${param.pn}'/> <!-- so this autom. gets converted to an int?? hmmm..-->
</ctherwise>
</c:choose>
<cut value='${iPhNo}'/> <!-- this never prints -->
Please UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the button.
In EL, It would convert a string into a number if it needs to perform any arithmetic operations on that variable. In your case it does not need to since you are just assigning a request parameter value to a variable. But your last c:out should print the value. Have you added the taglib directive for the "c"(core) tag?