简体   繁体   English

表单验证错误验证未处理

[英]Form validation error validation not processing

The following is my script : 以下是我的脚本:

<head>
<script type="text/javascript">
function del_form()
{
    var s_id=document.Delete.s_id;
    if(s_id.value != "")
    {
    //window.alert("Please enter the ID!");
    alert("Please enter the ID!");
    return false;
   }
 return true;
}
</script>

This the the form : 该表格:

<body>
  <form name="Delete" method="post" onsubmit=" return del_form()"     action="AdminDeleteShop2.jsp" >
Enter the ID of the Shop which is to be deleted : <input type="text" name ="s_id"     id="s_id">
<input type="submit" value="Delete!"><br>
</form><br><br>
<form name="Back" method="post" action="MasterMenu.jsp">
<input type="submit" value="Back">
</form><br><br>
</body>

The problem is that without performing form validation it is going onto the next page that is AdminDeleteShop2.jsp. 问题在于,如果不执行表单验证,它将转到AdminDeleteShop2.jsp的下一页。 And there it is giving me the following error : 这给了我以下错误:

org.apache.jasper.JasperException: An exception occurred processing JSP page /AdminDeleteShop2.jsp at line 26 : int s_id = Integer.parseInt(s_id_string);
root cause : java.lang.NumberFormatException: For input string: ""

Connection con = DriverManager.getConnection( host, uName, uPass );
 Scanner sc = new Scanner(System.in);
 String s_id_string = (String)request.getParameter("s_id");
 int s_id = Integer.parseInt(s_id_string);
 Statement stmt2 = con.createStatement();
 int check = stmt2.executeUpdate("delete from ShopSystem.Shop where s_id="+s_id+"");
 if(check>0)
 %> S_ID = <%= s_id %> has been deleted successfully.<br>   <%  
}
else
{   %>  Sorry the action cannot be completed. Please check if valid S_ID was     entered<br>                <%         
}
sc.close();
%>
<form name="Back" method="post" action="MasterMenu.jsp">
<input type="submit" value="Back">
</form><br><br>

kindly change your condition in script as below 如下更改脚本中的条件

function del_form(){

var s_id=document.Delete.s_id;

if(s_id.value == "")

{

 //window.alert("Please enter the ID!");

    alert("Please enter the ID!");

    return false;

   }

 return true;

}

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

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