gpt4 book ai didi

java - 表单验证错误验证未处理

转载 作者:行者123 更新时间:2023-12-01 12:40:01 25 4
gpt4 key购买 nike

以下是我的脚本:

<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>

这是表格:

<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>

问题是,如果不执行表单验证,它将进入下一页 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>

最佳答案

请按如下方式更改脚本中的条件

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;

}

关于java - 表单验证错误验证未处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25198224/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com