[英]How do I check for the null value in Java?
How to look for the value whether it is null or not in JSP. 在JSP中如何查找该值(无论它是否为null)。 Eg in below I want to check the description column in pipe table for null values.
例如在下面,我想检查管道表中的描述列是否为空值。
String Query1 = "SELECT description FROM pipe where pipe_id='" + id+"' and version_id=2";
SQLResult = SQLStatement.executeQuery(Query1);
SQLResult.first();
description = SQLResult.getString("description");
if(description=="")
{
json_string=json_string+"&desc="+description;
out.println("not null");
} else
{
json_string=json_string;
out.println("null");
}
Well: if (description != null && !description.isEmpty())
... however are you writing this code within a JSP ? 好吧:
if (description != null && !description.isEmpty())
...但是,您是否在JSP中编写此代码? That seems wrong. 好像错了 You should probably do this stuff within a servlet and pass the description as an request attribute to a jsp.
您可能应该在Servlet中执行此操作,并将描述作为请求属性传递给jsp。
或者,您可以使用StringUtils.isNotEmpty(description)
。
如果您确实在使用jsp,则应将描述存储在request属性中,然后使用<c:if test="${empty description}">
。
I use this personal method: 我使用这种个人方法:
public static boolean isNullOrEmpty(Object obj) {
if (obj == null || obj.toString().length() < 1 || obj.toString().equals(""))
return true;
return false;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.