Sto usando i tag JSTL. ho sotto il codice.imposta il valore booleano in variabile utilizzando i tag JSTL?
<c:set var="refreshSent" value="false"/>
Ora variabile refreshSent ha valore booleano o stringa?
Grazie!
Sto usando i tag JSTL. ho sotto il codice.imposta il valore booleano in variabile utilizzando i tag JSTL?
<c:set var="refreshSent" value="false"/>
Ora variabile refreshSent ha valore booleano o stringa?
Grazie!
che sta per essere un valore booleano. È possibile controllare confrontando in un
<c:if test="${refreshSent eq false}">
e
<c:if test="${refreshSent eq 'false'}">
Il secondo è un confronto di stringhe.
<c:set var="refreshSent" value="false"/>
Se l'espressione in value
restituisce String
; quindi il valore di var refreshSent
è di tipo String
.
Vedere http://docs.oracle.com/javaee/5/jstl/1.1/docs/tlddocs/ come riferimento.
C'è una conversione di tipo automatica dietro le quinte.
Vedi http://today.java.net/pub/a/today/2003/10/07/jstl1.html
Io lo uso per booleana
<c:set var="refreshSent" value="${false}"/>
<c:if test="${refreshSent}">
some code ........
</c:if>
Entrambi value = "$ {false}" e value = "false" valutano la stessa cosa nel test ... quindi se stai cercando di salvare caratteri, usa value = "false" (rinunciando al $ {} po...). –
Sì, è può essere booleano e stringa.
<c:if test="${refreshSent}">
your code...
</c:if>
oppure è possibile utilizzare come questo
<c:if test="${refreshSent eq 'false'}">
your code...
</c:if>
Grazie.
Penso che affermando esplicitamente che il primo avrà successo e il secondo fallirà chiarirò la risposta. So che è sciocco, ma io tendo ad andare per il codice e solo dopo leggere il testo. Grazie! – Cristopher