Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help on a null statement

Status
Not open for further replies.

chaddu1256

IS-IT--Management
Jan 13, 2003
28
0
0
US
<%
//to test for null values
String va5 = "";
if (request.getAttribute("meterNo").toString().equals("00000000")){
va5 = " ";
}
else{
va5 = request.getAttribute("meterNo").toString();
}
%>
<td><div align="center" class="sscolor1"><%= va5%>

Right now I have this code here that is checking a database table for a Meter Number, when the meter number is 00000000 then it just displays a blank, what I want to be able to do is have this statement check for 000000000 and "null" and display a blank if either is present. Is there a way to rewrite or modify this statement to check for both of these?
 
Hi,

OR CONDTION (One can be true)

<%if(null == request.getAttribute("meterNo") || request.getAttribute("meterNo").toString().equals("00000000")){%>
BLANK LINE
<%}else{%>
DISPLAY LINE
<%}%>

AND CONDITION (Both sholuld return true)

<%if(null == request.getAttribute("meterNo") && request.getAttribute("meterNo").toString().equals("00000000")){%>
BLANK LINE
<%}else{%>
DISPLAY LINE
<%}%>

I think in your case you are looking for OR codition.

Cheers,
Venu

 
Like Venur says, when checking a String, always check for null before checking .equals. Using the equals method on a null string will cause an exception, so it's always
Code:
if ((myString == null) || (myString.equals("")))
{
  do something;
}
Greg.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top