struts2中if标签使用注意事项

Q: Why won't the 'if' tag evaluate a one char string?
A:

If care is not taken with the quoting of literals, the expression language (OGNL) will misinterpret a char as a String.

Wrong
<s:if test="aStringProperty == 'A'">
  Why doesn't this work when myString is equal to A?
</s:if>

The solution is simple: flip the double and single quotes.

Right
<s:if test='aStringProperty == "A"'>
  This works!
</s:if>

Another solution is to escape the double quotes in the String.

Also Right
<s:if test="aStringProperty == \"A\"">
  This works too!
</s:if>

你可能感兴趣的:(struts2)