0

Hi i want to check the string in struts tag..
How to check whether the string1 conatins the string2 value?

for eg:

string1 = strutstag 
string2 = tag

i want to do some logic if string1 contains string2 value

help me to do this... thanks in advance

Siva Charan
  • 17,940
  • 9
  • 60
  • 95
Shakthi
  • 37
  • 1
  • 5
  • 17

1 Answers1

3

Try something like this:-

<s:if test="string1.indexOf(string2) != -1">
True
</s:if>

EDIT

As per your update, variable representation in IF condition is wrong. It should be represented with # symbol

<s:set name="string" value="%{'test'}" />
<s:set name="string1" value="%{'result'}" />
<s:if test="%{#counter.indexOf(#counter1) == -1}">
    <font size="5" color="green">String Not Found.</font>
</s:if>
<s:else>
    <font size="5" color="green">String Found.</font>
</s:else>

In your code, there is no counter related variable.

Your condition should be

<s:if test="%{#string.indexOf(#string1) == -1}">
Siva Charan
  • 17,940
  • 9
  • 60
  • 95
  • String Not Found. String Found. I have tried as like this but it always print the else part.. is any mistake i did in this – Shakthi Mar 09 '12 at 05:21
  • @Shakthi: for a variable, you should represent with `#` symbol (`#counter` and `#counter1`). – Siva Charan Mar 09 '12 at 05:47