Syed Daniyal Asif
Syed Daniyal Asif

Reputation: 736

JSP: simple IF condition not working

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

Upvotes: 2

Views: 342

Answers (2)

matt
matt

Reputation: 9401

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

Upvotes: 0

Braj
Braj

Reputation: 46841

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.

Upvotes: 1

Related Questions