方法一:
jsp中:
<c:if test="${param.message=='1'}">
<script>
alert('捐款成功,谢谢您的支持,祝您安康幸福!');
</script>
</c:if>
<c:if test="${param.message=='0'}">
<script>
alert('系统故障,操作失败,请重新添加!');
window.location = 'addView.jsp';
</script>
</c:if>
action中:
if (ok) {
response.sendRedirect("showLoveInHeartWeb?message=1");//1代表成功
}else{
response.sendRedirect("showLoveInHeartWeb?message=0");//0代表失败
}
方法二:
jsp中:
<script>
function check() {
var formname = document.form1;
if (formname.lname.value != "") {
alert("添加成功");
return true;
}
if (formname.lname.value == "") {
alert("姓名不能为空!");
formname.lname.focus();
return false;
}
}
</script>
<form action="addLoveInHeartWeb" method="post" onSubmit="return check(this)" name="form1">
<table border="1">
<tr><td><input type="text" name="lname"></td></tr>
<tr><td><input type="submit" value="提交"></td></tr>
</table>
</form>
---恢复内容结束---
---恢复内容结束---