【问题标题】:check parameter is valid or not in jspjsp中检查参数是否有效
【发布时间】:2012-10-22 21:45:48
【问题描述】:

我只是想检查传递给 jsp 的参数是否为 null 或不使用 httpcontext,所以我怎么能做到这一点

case_yr = Integer.parseInt(request.getParameter("case_yr"));
sub_type_int =Integer.parseInt(request.getParameter("sub_type_int"));
String case_num = request.getParameter("case_num");
String lang_mode = request.getParameter("lang_mode");
String mobile_no = request.getParameter("caller_id");
String dialled_id = request.getParameter("dialled_id");

我想上面的值是否有效我正在将值从 xml 页面提交到 jsp 页面并使用 request.getparameter() 在 jsp 中获取值

所以请告诉如何检查值是否为空,并且没有 sevlet 只有 vxml 页面和 jsp 页面

【问题讨论】:

  • “有效”是什么意思? ..你的意思是测试请求属性是否为空?

标签: java jsp vxml


【解决方案1】:

如果要检查请求属性是否为null,只需检查它们是否为null 这种方式

String case_num = request.getParameter("case_num");
if(case_num!=null){
    //do your logic
 }
 else {
  System.out.println("case_num is null");
  }
 int number ;
String num = request.getParameter(num);
 if(num!=null){
     number = Integer.parseInt(num);
   }
 else {
  System.out.println("case_num is null");
  }

【讨论】:

  • 如果有 int 代替 string 那么怎么做
  • 我已经做到了,但我想在 httpcontext 级别做到这一点,那么如何做到这一点
【解决方案2】:

使用 JSTL

<c:if test="${not empty case_num}">
    case_num is NOT empty or null.
</c:if>

【讨论】:

    【解决方案3】:

    您可以使用以下代码检查有效参数。

    String value = request.getParameter("case_yr")
    if(value != null)
       case_yr = Integer.parseInt(value );
    
    String value1 = request.getParameter("sub_type_int");
    if(value1 != null)
       sub_type_int =Integer.parseInt(value1 );
    

    【讨论】:

      猜你喜欢
      • 2012-06-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-07
      • 2013-06-24
      • 2015-04-11
      • 1970-01-01
      • 2013-03-06
      • 1970-01-01
      相关资源
      最近更新 更多