Null is an important part of any advance programming language. Java also takes the advantage of null and null exceptions. Sometime we know null is not part of design and string. We do not want to show to user and client. This time we have to remove null from our string and text.
Null can be removed by easiest method by declaring a method in code.
Make a common method in declarative in JSP or in java. Return method with string. If string containing null, remove with blank If string is not containing null, return same string.
Code example
<%@ page contentType="text/html; charset=iso-8859-1" language="java" %> <%! public String nullconv(String str) { if(str==null) str=""; else if(str.equals("null")) str=""; else if((str.trim()).equals("")) str=""; else if(str.equals(null)) str=""; else str=str.trim(); return str; } %> <% String myString=null; %> <html> <head> <title>Remove null from string</title> </head> <body> This string not contain null ::: <%=nullconv(myString)%> </body> </html>




Link to Us