2

I am new on JSP. My simple if condition is not working properly.

//row.getString("labels.above") is taken from database its value is "true"

< input type="radio" <% if(row.getString("labels.above")=="true"){ %><%="checked" %><% } %> />True 

but it is not marking check on radio button.

this condition must be true. as
this:

 <%=row.getString("labels.above")%>:<%="true" %>  

Output:

true:true
Braj
  • 46,415
  • 5
  • 60
  • 76
Syed Daniyal Asif
  • 726
  • 1
  • 5
  • 19

2 Answers2

1

For String comparison use String#equals() method instead of ==

It should be

"true".equals(row.getString("labels.above"))

I suggest you to use JavaServer Pages Standard Tag Library or Expression Language instead of Scriplet that is more easy to use and less error prone.

Braj
  • 46,415
  • 5
  • 60
  • 76
0

Don't compare strings in java using the == operator.

The short story is that == will test to see if the two strings reference the exact same object, while the .equals method will test if the strings match character-for-character. In almost all cases, you want to check using .equals

Community
  • 1
  • 1
matt
  • 9,113
  • 3
  • 44
  • 46