Notes on the use of if tags in struts2

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>

Intelligent Recommendation

struts2 own project showcase of tags study notes

[size = x-large] struts2 item carrying the tags showcase study notes [/ size] [Size = x-large] of the first [/ size], we look first non-ui label. There are a few caveats: [size=large]1.actionTag[/size...

J2EE series of Struts2 study notes (17)-Struts2 tags (interface tags, other tags)

Now learn about Struts2 interface tags and two other commonly used tags. 1. The interface labels of Struts2 include: Form label: form submission label; Text tag: text tag; Radios tag: single selection...

[Struts2 study notes] 8: Control tags in Strut2, non-form tags

Follow the examples in the book. The control tab only learns branch control and loop control. The latter also only learn common or special ones. These tags will more or less use the built-in OGNL expr...

Struts2--Use tags to prevent duplicate submissions

Take a small example: This is the web page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 <body>     <s:actionerror/>   <s:form action= "LoginAction" method= &qu...

[Web Development] Use of Struts2 tags-form UI tags

Common attributes Template related properties: templateDir: used to specify the directory of the template file used by the label. theme: Used to specify the theme used by the tag. template: Used to sp...

More Recommendation

[Web Development] Use of Struts2 tags-non-form UI tags

1. actionerror: used to output the error message returned by the getActionErrors() method of the Action instance 2. actionmessage: used to output the error message returned by the getActionMessage() m...

struts2 tags

1.       createwebEngineering, addstruts2Required by the frameworkjarpackage. 2.       Add tostruts2Filter to support. 3. &nb...

Struts2 tags and jsp page Java code values ​​use each other

Business needs: The Struts tag uses the value of the list in the Jsp page, and the java code uses the value from Struts.      ...

Struts2 control tag (a) S: if, S: elseif and S: else tags use

1. First build the Struts2 environment After the new Web project is created, the Struts2 rack package (which can be downloaded from Struts) is tested under the lib directory. 2. First create an Action...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top