3

I am new to struts and I was thinking if we can implement OR and AND conditions with struts logic:equal? if not then what are the alternatives.

3 Answers 3

2

for AND like if(Column1 == "1" && Column2 == "2") { .... }

you can use :

<logic:equal name="urList" property="Column1" value="1">
  <logic:equal name="urList" property="Column2" value="2">
  doSomeThing
  </logic:equal>
</logic:equal>

or for 'OR' :

<logic:equal name="urList" property="Column1" value="1">
  doSomeThing
</logic:equal>
<logic:equal name="urList" property="Column2" value="2">
  doSomeThing
</logic:equal>

sry for bad english.

4
  • Unfortunately this OR implementation does doSomeThing twice if both conditions are met Sep 19, 2017 at 12:58
  • how can u do, to amke it doSomeThing ( in OR condition) but just once? Oct 19, 2018 at 14:02
  • @PetrÚjezdský ty Oct 19, 2018 at 14:02
  • 1
    You have to negate the first statement in the second one using logic:notEqual and then nest your "OR" branch. Oct 22, 2018 at 7:33
1

You can use EL with Strut's taglib. You can also use JSTL (c:if in this case).

-1

use JSP scriptlet instead of logic: equals

if(string.equals("Rejected") || string.equals("selected")){
do someting
}

In JSP:

<%if(string.equals("Rejected") || string.equals("selected")){
do someting
}%>
1
  • Never use scriptlets, it's an antipattern Feb 13 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.