就是說在登錄頁頁判斷用戶名和密碼,不用提交到另外一頁

解决方案 »

  1.   

    写表单提交的时候,action不写值不就可以了,让它提交到它本身页面,
      

  2.   

    表单的ACTION=后面写自己这个页面或者不写就可以了
      

  3.   

    <%@page contentType="text/html; charset=UTF-8" language="java"
    import="java.sql.*" errorPage=""%>
    <jsp:useBean id="db" class="blog.DBConnection" scope="page" />
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" type="text/css" href="/skin/css.css">
    <title>User Login</title>
    <script language="javascript">
    <!--
      function checkUsernameAndPassword()
      {
        if(form1.username.value.length<=0)
    {
      alert("Input the username please!");
              form1.username.focus();
              return false;
    }
    if(form1.password.value.length<=0)
    {
      alert("Input the password please!");
              form1.password.value.focus();
              return false;
    }
    return true;
      }
    //-->
    </script>
    </head>
    <body>
    <link rel="stylesheet" type="text/css" href="skin/css.css">
    <TABLE cellSpacing=0 cellPadding=0 width=750 align=center CLASS="top">
    <TR>
    <TD class="main">
    </TD>
    </TR>
    </TABLE>
    <TABLE cellSpacing=0 cellPadding=0 width=750 align=center CLASS="top">
    <TR>
    <TD height=22 bgcolor=#000000>
    &nbsp;&nbsp;&nbsp;
    <FONT color=#ffffff>WELCOME COME TO MY BLOG</FONT>
    </TD>
    </TR>
    </TABLE>
    <TABLE width=750 cellSpacing=0 cellPadding=0 align=center
    bgColor=#ffffff CLASS="top">
    <TR>
    <TD>
    &nbsp;
    </TD>
    <TD width=100% vAlign=top cellSpacing=0 cellPadding=0 align=center
    bgColor=#f7f7f7>
    <TABLE width=100% cellSpacing=4 cellPadding=0>
    <TR>
    <TD bgColor=#dbdbdb>
    <p>
    &nbsp;
    </p>
    <p>
    &nbsp;
    </p>
    <p>
    &nbsp;
    </p>
    <p>
    &nbsp;
    </p>
    <%
    String action = request.getParameter("action");
    if (action == null) {
    %>
    <form name="form1" method="post" action="Login.jsp?action=login">
    <table width="200" border="0" align="center"
    bordercolor="#000000" cellpadding="0" cellspacing="10">
    <tr>
    <td>
    <div align="center">
    USERNAME:
    </div>
    </td>
    <td>
    <div align="center">
    <input name="username" type="text" id="username" size="16">
    </div>
    </td>
    </tr>
    <tr>
    <td>
    <div align="center">
    PASSWORD:
    </div>
    </td>
    <td>
    <div align="center">
    <input name="password" type="password" id="password"
    size="18">
    </div>
    </td>
    </tr>
    </table>
    <table width="200" border="0" align="center">
    <tr>
    <td>
    <div align="center">
    <input type="submit" name="Submit" value="Submit"
    onClick="return checkUsernameAndPassword()">
    </div>
    </td>
    <td>
    <div align="center">
    <input type="reset" name="Submit2" value="Reset">
    </div>
    </td>
    </tr>
    </table>
    </form>
    <%
    } else {
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    try {
    ResultSet rs = db
    .executeSQL("select password,admin from admin where admin='"
    + username + "'");
    while (rs.next()) {
    if ((rs.getString("password").equals(password))
    || (rs.getString("admin").equals(""))) {
    response.sendRedirect("index.jsp"); } else {
    %>
    <script language="javascript">alert("the username or password is wrong!");</script>
    <%
    }
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    %>
    <p>
    &nbsp;
    </p>
    <p>
    &nbsp;
    </p>
    <p>
    &nbsp;
    </p>
    <p>
    &nbsp;
    </p>
    <p>
    &nbsp;
    </p>
    <p>
    &nbsp;
    </p>
    </TD>
    </TR>
    </TABLE>
    </TD>
    </TR>
    </TABLE>
    <TABLE height=28 cellSpacing=0 cellPadding=0 width=750 align=center
    bgColor=#808080 CLASS="bom">
    <TR>
    <TD align=RIGHT height=28>
    &copy;
    <strong> <font color="#FFFFFF">Www.9955.Cc</font> </strong> All
    rights reserved. &nbsp;&nbsp;&nbsp;
    </TD>
    </TR>
    </TABLE>
    </body>
    </html>
    請幫我看一下,用戶名或密碼錯誤之后不會自動轉向登陸框那里
      

  4.   

    登入前获取数据源  
    填写用户名和密码后 用javascript静态校验