Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP with a if-statment problem

 
marko markovic
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
here is my source code where i have problem:
<table width="100%" border=1 bgcolor="1188cc" bordercolor="#1177cc">
<% for (int i=0; i<Vector.size(); i++){
JspCriterium theJspCriterium = (JspCriterium)Vector.elementAt(i);
System.out.println(Vector.getName()+" "+theJspCriterium.getDescription()+" "+theJspCriterium.getComponentName());
if (theJspCriterium.isVisible()){
%>
<tr>
<td width="2%" bgcolor="1144cc" align="center">
<% if (theJspCriterium.isSelected()){ %>
<input type=checkbox NAME="ckbxs" VALUE="check" CHECKED>
<b><font name="Verdena" size="3" color="#FFFFFF">
</font></b>
<% }
else { %>
<input type=checkbox NAME="ckbxs" VALUE="check">
<b><font name="Verdena" size="3" color="#FFFFFF">
</font></b>
<% }%>
</td>
<% if(theJspCriterium.getComponentName()=="text "){
System.out.println("IF "+theJspCriterium.getName()+" "+theJspCriterium.getDescription()+"
"+theJspCriterium.getComponentName()); %>
<td width="20%" bgcolor="1144cc" align="right">
<b><font name="Verdena" size="3" color="#FFFFFF"> <%= theJspCriterium.getDescription()%>
</font></b>
</td>
<td>
<input width="78%" type=text value="<%= theJspCriterium.getValue()%>" name="texte"
size=55 maxlength=256 >
</td>
<% }%>
</tr>
<% }
} %>

</table>
With these if(theJspCriterium.getComponentName()=="text ") i have a problem. the getComponentName()
is a method with a returned String value. I can write the value on the screen but i couldn't do the
if.
I don't know why?
Could anyone help through, please?
$Regards
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java to compare Strings you should always use the "equals" method. The "==" operator just compares the references.
Your if should read:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic