This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Servlets and the fly likes JSP with a if-statment problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "JSP with a if-statment problem" Watch "JSP with a if-statment problem" New topic
Author

JSP with a if-statment problem

marko markovic
Greenhorn

Joined: Mar 16, 2001
Posts: 28
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

Joined: Jan 07, 1999
Posts: 6920
In Java to compare Strings you should always use the "equals" method. The "==" operator just compares the references.
Your if should read:


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
 
Consider Paul's rocket mass heater.
 
subject: JSP with a if-statment problem