简体   繁体   English

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

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

I'll be receiving an HTTP URL with three input parameters.我将收到一个带有三个输入参数的 HTTP URL。 In that one of the parameter is a string and other two of integer values.其中一个参数是一个字符串,另外两个是整数值。

I want to check whether all three request parameters are present or not.我想检查所有三个请求参数是否都存在。 Also, I need to check all the input parameters is null or not..另外,我需要检查所有输入参数是否为空。

Example - http url:示例 - http 网址:

http: //....../a=123456&b=12345678&c=y 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.
}

If the request parameter is not present it will be null.如果请求参数不存在,它将为空。 If it is present but has no data set, it will be an empty string.如果它存在但没有数据集,它将是一个空字符串。

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

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