• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSP with a if-statment problem

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
reply
    Bookmark Topic Watch Topic
  • New Topic