Java 表单验证错误验证未处理
以下是我的脚本:Java 表单验证错误验证未处理,java,forms,jsp,Java,Forms,Jsp,以下是我的脚本: <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; }
<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>
函数del_form()
{
var s_id=document.Delete.s_id;
如果(s_id.value!=“”)
{
//window.alert(“请输入ID!”);
警报(“请输入ID!”);
返回false;
}
返回true;
}
此表格如下:
<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>
输入要删除的店铺的ID:
问题在于,如果不执行表单验证,它将进入下一个页面AdminDeleteShop2.jsp。
它给了我以下的错误:
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>
org.apache.jasper.jaspereException:在第26行处理JSP页面/AdminDeleteShop2.JSP时发生异常:int s_id=Integer.parseInt(s_id_string);
根本原因:java.lang.NumberFormatException:用于输入字符串:“”
Connection con=DriverManager.getConnection(主机、uName、uPass);
扫描仪sc=新的扫描仪(System.in);
字符串s_id_String=(String)request.getParameter(“s_id”);
int s_id=Integer.parseInt(s_id_字符串);
语句stmt2=con.createStatement();
int check=stmt2.executeUpdate(“从ShopSystem.Shop中删除,其中s_id=“+s_id+”);
如果(检查>0)
%>S_ID=已成功删除。
很抱歉,操作无法完成。请检查是否输入了有效的S_ID
请在下面的脚本中更改您的条件
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;
}