注册 登录
编程论坛 JavaScript论坛

java 代码没阻止表单提交

七号 发布于 2010-11-10 18:54, 669 次点击
<%@ 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>
2 回复
#2
aspic2010-11-11 09:50
你可以这样测试
function check1(){
    return false
}
如果没能提交说明OK
反之应该是你里面各项的判断有问题 逐一排查之
#3
七号2010-11-11 12:19
谢谢了  我知道了javascript 代码为什么没有执行 因为里面不能嵌套表达式
1