http://www.4ucode.com/Study/Topic/367889
————————————————————————————————————————————————————————
今天用struts2的if标签作一个判断,死活到不了if里面,代码如下:
<s:if test="namePinYin == 'a'">hello</s:if>
页面也不报错,而且也测试了namePinYin的确等于a
后来发现服务器报了个NumberFormatException,信息如下:
Caught an exception while evaluating expression 'namePinYin == 'a'' against value stack
java.lang.NumberFormatException: For input string: "a"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1224)
google了一下,发现问题其实很简单,namePinYin是个字符串,test的时候需要这样写:
<s:if test='namePinYin == "a"'>hello</s:if>
照这样看,单引号可能会用于比较数字类型,详细可以查看一下官方的faq:
http://struts.apache.org/2.x/docs/why-wont-the-if-tag-evaluate-a-one-char-string.html
<s:if test="aStringProperty == 'A'">
Why doesn't this work when myString is equal to A?
</s:if>
<s:if test='aStringProperty == "A"'>
This works!
</s:if>
<s:if test="namePinYin == 'a'">hello</s:if>
页面也不报错,而且也测试了namePinYin的确等于a
后来发现服务器报了个NumberFormatException,信息如下:
Caught an exception while evaluating expression 'namePinYin == 'a'' against value stack
java.lang.NumberFormatException: For input string: "a"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1224)
google了一下,发现问题其实很简单,namePinYin是个字符串,test的时候需要这样写:
<s:if test='namePinYin == "a"'>hello</s:if>
照这样看,单引号可能会用于比较数字类型,详细可以查看一下官方的faq:
http://struts.apache.org/2.x/docs/why-wont-the-if-tag-evaluate-a-one-char-string.html
<s:if test="aStringProperty == 'A'">
Why doesn't this work when myString is equal to A?
</s:if>
<s:if test='aStringProperty == "A"'>
This works!
</s:if>