[英]Redirect to same Html page with error
I am trying to redirect to the same HTML page with an error message saying all fields are required if any of the fields are left empty. 我试图重定向到同一HTML页面,并显示一条错误消息,指出如果任何字段为空,则所有字段都是必需的。 I am using Servlets, MYSQL, and HTML to build this project, I am able to store data in MYSQL but stuck at this point, Please help me.
我正在使用Servlets,MYSQL和HTML来构建此项目,我能够将数据存储在MYSQL中,但此时仍卡住,请帮助我。
You can use RequestDispatcher to dispatch your HTML resource. 您可以使用RequestDispatcher调度HTML资源。 But you need to handle displaying error messages in client side (using JS).
但是您需要处理在客户端显示错误消息(使用JS)。 But it's better to use JSP, so you can achieve it easily
但是使用JSP更好,因此您可以轻松实现它
Well, since you didn't show any code, the whole idea is: 好吧,由于您没有显示任何代码,所以整个想法是:
validate.js
validate.js
var field = document.forms["form_name"]["user_input"].value;
if (field==null) {
alert("all fields are required");
return false;
}
validate.php
validate.php
if(isset($_POST["user_input])){
$field = $_POST["user_input"];
if(empty($field){
echo "error, all fields are required"
}
Hope this helps 希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.