问道EL问题
<html> <body>
${(5 + 3 + a > 0) ? 1 : 2}
</body> </html>
Select the correct statement from the options below:
a It will print 1 because the statement is valid.
b It will print 2 because the statement is valid.
c It will throw an exception because a is undefined.
d It will throw an exception because the expression’s syntax is invalid.
为什么答案是a?
是把表达式中的a看作字符 'a '吗?是97吗?
请高手高知小弟,谢谢!
------解决方案-------------------- <html> <body>
${(5 + 3 + a > 0) ? 1 : 2}
</body> </html>
在这里的a应该是看作一个变量,而这个变量为null,在调用中需要转换为Number的时候会返回一个0,所以${5+3+a} = 8
我们可以做一个试验,在前面定义一个a <c:set var= "a " value= "10 " />
那么 ${5+3+a} = 18