[英]message after form validation
I have a JSP page which has several input fields and a servlet validates the fields when I click on the submit button and redirects to another page. 我有一个JSP页面,其中包含几个输入字段,当我单击“提交”按钮并重定向到另一个页面时,servlet会验证这些字段。
I would like to add a popup window: "all the fields are ok" after a correct server-side validation. 我想添加一个弹出窗口:正确的服务器端验证后,“所有字段都可以”。
So I started with: 所以我开始:
<form ="alert('success');">
<input type="submit" value="submit">
</form>
The problem is that "success" is printed even if the fields are incorrect. 问题是即使字段不正确,也会打印“成功”。
I thought about setting a parameter in the protected void doPost(HttpServletRequest
request, HttpServletResponse
response, which calls an execute() function to say if things are OK or not but I do not know how to get this parameter just after the submit so I could make a conditional: 我考虑过在受保护的void doPost(HttpServletRequest
请求, HttpServletResponse
响应)中设置一个参数,该参数调用execute()函数来表示一切是否正常,但是我不知道如何在提交后立即获取此参数,所以我可以有条件的:
if (checkSubmitParameter == OK )
callsPopup()
Try something like this (see jsfiddle ): 尝试这样的事情(请参阅jsfiddle ):
<script>
function checkit(){
var val = document.getElementById('txt').value;
if(val == "good"){
alert("success");
}else{
alert("failure!");
}
}
</script>
<form onsubmit='checkit()'>
<input type='text' id="txt" />
<input type='submit' value='Submit' />
</form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.