直接在Jsp中判断表单是否为空:
<form name="myForm" action="login" method="post" οnsubmit="return checkForm()">
<script type="text/javascript">
function checkForm(){
var userName = document.getElementById("userName").value;
var password = document.getElementById("password").value;
if(userName == null || userName == ""){
document.getElementById("error").innerHTML=("用户名不能为空!");
return false;
}else if(password == null || password == ""){
document.getElementById("error").innerHTML=("密码不能为空!");
return false;
}
return true;
}
</script>
Document:
在获取某一个值的时侯:
var userName = document.getElementById("userName").value;
var password = document.getElementById("password").value;
当给${}EL表达式设置值的时候:
document.getElementById("error").innerHTML=("xxx");