繁体   English   中英

如何检查输入参数的值是否为空

[英]How to check whether values for input parameters is null or not

我将收到一个带有三个输入参数的 HTTP URL。 其中一个参数是一个字符串,另外两个是整数值。

我想检查所有三个请求参数是否都存在。 另外,我需要检查所有输入参数是否为空。

示例 - http 网址:

http: //....../a=123456&b=12345678&c=y

String a = request.getParameter("a");
String b = request.getParameter("b");
String c = request.getParameter("c");

if(a != null && !a.isEmpty()) {
    //Do something with a.
}

if(b != null && !b.isEmpty()) {
    //Do something with b.
}

if(c != null && !c.isEmpty()) {
    //Do something with c.
}

如果请求参数不存在,它将为空。 如果它存在但没有数据集,它将是一个空字符串。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM