您的位置:首页 > 编程语言 > Java开发

struts2 tag if NumberFormatException

2012-09-17 10:52 155 查看
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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: