有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java输入文本验证错误JSP

我有一个输入文本,比如用来输入价格。 在用户单击insertproducts.jsp上的提交按钮后,我在doinsertproducts.jsp上有验证代码

输入价格的验证为:

  1. 必须填写输入文本
  2. 输入文本必须是数字
  3. 价格必须大于零

以下是第一个代码:

if(price.equals("")||price==null){
    response.sendRedirect("../insertproducts.jsp?insertproduct="+producttype+"&err=Price must be filled.");
    return;
}
else{
        try{
            intprice=Integer.parseInt(price);
        }
        catch (Exception e) {
            response.sendRedirect("../insertproducts.jsp?insertproduct="+producttype+"&err=Price must be numeric.");
        }
    }

我不知道我必须把第二个代码放在哪里来检查输入是否小于1:

if(intprice<1){
            response.sendRedirect("../insertproducts.jsp?insertproduct="+producttype+"&err=Price must be greater than 0 (zero).");
    }

无论如何,当我执行第一个代码并尝试将字符输入inputtext(不包括第二个代码)时,有一个根本原因错误:

Cannot call sendRedirect() after the response has been committed

看起来代码没有处理这个错误。 有什么解决方案可以让代码检测到用户的3个错误吗


共 (0) 个答案