Thursday, September 8, 2011

Java Interview Questions - 67

Q: How can I prevent the word "null" from appearing in my HTML input text fields when I populate them with a resultset that has null values?
A: You could make a simple wrapper function, like
<%!
String blanknull(String s) {
return (s == null) ? \"\" : s;
}
%>
then use it inside your JSP form, like
<input type="text" name="lastName" value="<%=blanknull(lastName)% >" >

No comments: