handling null values in text box in jsp

Vicky picture Vicky · Nov 22, 2011 · Viewed 9.6k times · Source

Say a text box takes value from Transfer Object as below in a jsp:

<INPUT TYPE="text" NAME="test" ID="test" value="<%=testTO.getTest()%>">

However, if getTest returns null, null will be displayed.

How to use ? : with scriptlet so that if the value is null, blank is displayed else the value returned from TO.

Answer

dku.rajkumar picture dku.rajkumar · Nov 22, 2011
testTO.getTest() == null ? "" : testTO.getTest()

try this , it will surely work.