java 代码没阻止表单提交
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%@page import="entity.Userinfo"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'login.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">
function check1(){
if(document.getElementById("oldpwd").value=="" || document.getElementById("pwd").value=="" ||document.getElementById("pwd1").value=="" ){
<%
session.setAttribute("Tip","*信息输入不完整 ");
%>
return false;
}
String oldpwd=document.getElementById("oldpwd").value;
<%
Userinfo u=(Userinfo)session.getAttribute("User");
%>
if(oldpwd!=u.getUserpwd()){
<%
session.setAttribute("Tip","*旧密码输入错误 ");
%>
return false;
}
if(document.getElementById("pwd").value!=document.getElementById("pwd1").value){
<%
session.setAttribute("Tip","*两次密码输入不一致 ");
%>
return false;
}
return true;
}
</script>
</head>
<body>
<form action="Userserver?op=update" method="post" onsubmit="return check1();">
<table border="1" align="center">
<caption>
<%
if(session.getAttribute("Tip")!=null){
%>
<span style="color:red"><%=session.getAttribute("Tip") %></span>
<%
}
%>
</caption>
<tr>
<td colspan="2" bgColor="blue">修改密码</td>
</tr>
<tr>
<td >旧密码:</td><td><input type="password" name="oldpwd" id="oldpwd"></td>
</tr>
<tr>
<td >新密码:</td><td><input type="password" name="pwd" id="pwd"></td>
</tr>
<tr>
<td >确认密码:</td><td><input type="password" name="pwd1" id="pwd1"></td>
</tr>
<tr>
<td colspan="2" align="center" ><input type="submit" value="修改"><input type="button" value="返回" click="history.go(-1); "></td>
</tr>
</table>
</form>
</body>
</html>