-1

Is there any gun shot method to find and check for a null string without getting into exceptions??

Please do not suggest StringUtils class please. I tried everything but i am a not able to compile that with the project. I am using Tomcat and I am programming in the root folder of the tomcat and i have several jsp files which i am not able to link with StringUtils. I am programming using Dreamweaver.

Please Help,

Bimalesh Jha
  • 1,464
  • 9
  • 17
Abhijeet
  • 84
  • 1
  • 3
  • 9
  • You can open the source code of Apache StringUtils.isBlank or isNull and use the same code within your project. – RaceBase Jul 09 '13 at 05:37

2 Answers2

1

Anything wrong with the usual way?

if (str == null)

If by "null" you mean "blank" also, then

if (str == null || str.trim().isEmpty())
Bohemian
  • 412,405
  • 93
  • 575
  • 722
0

If you want to use like a function in jsp do following:

<%!
 // define a isNull() function
 static boolean isNull(String x){
    return (x == null || x.isEmpty());
 }
%>

then you can use above function anywhere inside JSP like 

<% if (isNull(xxx)){ %>
// html code
<% } %>
Bimalesh Jha
  • 1,464
  • 9
  • 17
  • Thanks sooo much... I am loving this.... Doing this project for a temple.... So you all will get transcendental credit... – Abhijeet Jul 09 '13 at 12:57