表单提交问题

时间:2011-11-03 16:51:38

标签: javascript html jsp

我使用了以下代码....

  <html>
<head>
    <% String loginstatus=request.getParameter("loginstatus");
       String option=request.getParameter("option");
        //out.println(option);
%>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>LOGIN PAGE</title>
    <link href="style/style.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" language="javascript">
        function validate(uname,pwd){
            var username,password;
            username=uname.value;
            password=pwd.value;
            if(username=="" && password==""){
                alert("Please enter your username and password");
            }else if(username=="")
                alert("Username filed shouldn't be empty");
            else if(password=="")
                alert("Password filed shouldn't be empty");
            else{
                return true;
            }
            return false;
        }
        function forgetpwdformvalidaton(){
            alert("The Page Under Progress");
            return false;
        }
        function pwd(pwdissue){
            var pwddecision=pwdissue.value;
            //alert(pwddecision);
            window.open('loginpagevalidation.jsp?option='+pwddecision,target="_self");
        }
    </script>
</head>
<body>
    <center>
        <%
           Connection con;

           Statement stmt;

       ResultSet rs;

            System.out.print("Oracle data base connectivity.......");

    try{

                Class.forName("oracle.jdbc.driver.OracleDriver");

                    con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","sfts","sfts");

                    stmt=con.createStatement();

                    System.out.println("Success");

                    session.setAttribute("connection", con);
                    session.setAttribute("statement", stmt);

                    System.out.println("Session keys are ready");
                }
                catch(Exception e)
                {

        System.out.println(e);
                }                     
            %>
        <div id="border">
        <div style="border-bottom:1px solid #DEDEDE; border-left:1px solid #DEDEDE; width:1090px;">
             <div class="heading-bg">SALES FORCE TRACKING SYSTEM</div>
            <div class="main">
                <%if(loginstatus!=null && loginstatus.equals("mismatch")){
                    %><h1 class="errormessage">INVALID USERNAME OR PASSWORD.</h1><%
                }%>
               <form name="loginform" onsubmit="return validate(uname,pwd)" action="loginpagevalidation.jsp">
                        <table name="logintable">
                            <caption>SignIn Here</caption>
                            <tr class="tableevenrow"><td>UserName</td><td><input type="text" name="uname" /></td></tr>
                            <tr><td>Password</td><td><input type="password" name="pwd"/></td></tr>
                            <tr class="tableevenrow"><td></td><td><input type="submit" name="submit" value="SIGNIN"/><input type="reset" onclick="managersigning.html" name="reset" value="RESET"/></td></tr>
                            <tr><td></td><td><a href="signup.jsp"> Click here to SingUp</a></td></tr>
                        </table>
                </form>

                <%if(option==null){%>
                    <input type="radio" name="pwdissue" onclick="pwd(this)" value="forget"/>Forget Password
                    <input type="radio" name="pwdissue" onclick="pwd(this)" value="ChangePassword"/>Reset Password
                    <%}else if(option!=null && option.equals("forgetpwd")){%>
                        <input type="radio" name="pwdissue" checked  value="forget"/>Forget Password
                        <input type="radio" name="pwdissue" onclick="pwd(this)" value="reset"/>Change Password
                        <form onclick="forgetpwdformvalidation()" action="">
                            <table>
                                <tr class="tableevenrow"><td>Enter EmployeeID</td><td><input type="text" name="eid"></td></tr>
                                <tr><td>Enter EmailID</td><td><input type="text" name="mailid"></td></tr>
                                <tr class="tableevenrow"><td></td><td><input type="submit" name="sendmail" value="Reset and send password to me"></td></tr>
                            </table>
                        </form>
                    <%}else if(option!=null && option.equals("resetpwd")){%>
                        <input type="radio" name="pwdissue" onclick="pwd(this)" value="forget"/>Forget Password
                        <input type="radio" name="pwdissue" checked value="reset"/>Change Password
                        <form onsubmit="return resetpwdvalidation()" action="">
                            <table>
                                <tr class="tableevenrow"><td>Enter EmployeeID</td><td><input type="text" name="eid"></td></tr>
                                <tr class=""><td>Enter Old Password</td><td><input type="text" name="oldpwd"></td></tr>
                                <tr class="tableevenrow"><td>Enter New Password</td><td><input type="text" name="newpwd"></td></tr>
                                <tr><td></td><td><input type="submit" name="sendmail" value="Change My Password"></td></tr>
                            </table>
                        </form>
                    <%}%>
            </div>
        </div>
   </center>
</body>
</html>

输出屏幕为: screenshot

我的问题是每当我点击'ForgetPassword'或'ResetPassword'时,应该调用相应的java脚本函数,而是指向loginvalidation.jsp? 这是什么问题...... ??

3 个答案:

答案 0 :(得分:3)

看起来pwd()是你正在调用的函数吗?

<input type="radio" name="pwdissue" onclick="pwd(this)" value="forget"/>Forget Password

哪个重定向到loginpagevalidation.jsp

function pwd(pwdissue){
    var pwddecision=pwdissue.value;
    //alert(pwddecision);
    window.open('loginpagevalidation.jsp?option='+pwddecision,target="_self");
}

我错过了什么吗?

答案 1 :(得分:2)

您的pwd函数会打开一个'loginpagevalidation.jsp'窗口;那就是你说想要发生什么?

那些应该是链接,而不是单选按钮。你真的在JSP中做SQL工作吗?由于各种原因,这不应该通过任何人的代码审查:(

为了将来参考,最好只包含与问题实际相关的代码,而不是整个页面的源转储。我删除了一些不重要的HTML。

答案 2 :(得分:1)

这是javascript函数pwd taht调用url loginpagevalidation.jsp,因此您的函数确实被执行,但也会立即重定向到新的url。这不是你想要的吗?