http://expert.csdn.net/Expert/topic/1692/1692167.xml?temp=.8294794那里有我帖的代码。

解决方案 »

  1.   

    谢谢,不过你的那个 cardBean.java编译不了,好像有问题
      

  2.   

    我给你:
    <html>
    <head>
    <title>用户登录</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <style type="text/css">
    <!--
    td {
        font-size: 12px;
        line-height: 120%;
    }
    -->
    </style>
    <style type="text/css">
    <!--
    .link1 {
        font-size: 12px;
        font-weight: bold;
        color: #040095;
        text-decoration: none;
    }
    .link1:hover {
        font-size: 12px;
        font-weight: bold;
        color: #FF0000;
        text-decoration: underline;
    }
    -->
    </style></head><body background="images/bg_whole.gif" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
    <center>
      <br>
      <br>
      <br>
      <br><form  name="login" method="post" action="login_check.jsp">  <table width="576" border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <td align="left" valign="top">
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
          <td width="185" height="55" align="left" valign="top"colspan="1"><img src="images/company/gzdx/logo1.gif" width="180" height="55"></td>
          <td width="391" align="center" valign="top" colspan="2"><img src="images/company/gzdx/cmpy_name1.gif"  height="55"></td>
          </tr>
          </table>
          </td>
        </tr>
        <tr>
          <td align="left" valign="top"><table width="576" height="291" border="0" cellpadding="0" cellspacing="15" bgcolor="#8EBCEE">
              <tr>
                <td align="left" valign="top" bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr> 
                      <td height="25" colspan="4">&nbsp;</td>
                    </tr>
                    <tr> 
                      <td width="18">&nbsp;</td>
                      <td width="283"><img src="images/xx.jpg" width="273" height="208"></td>
                      <td width="235" align="left" valign="top"><table width="235" height="208" border="0" cellpadding="0" cellspacing="0" bgcolor="#CFCFCF">
                          <tr align="left" valign="middle"> 
                            <td height="25" colspan="3">&nbsp;&nbsp;<font color="#CF090A">请输入登录信息</font></td>
                          </tr>
                          <tr> 
                            <td width="8">&nbsp;</td>
                            <td height="129" align="left" valign="top" bgcolor="#FFFFFF"><table width="100%" height="129" border="0" cellpadding="0" cellspacing="0">
                                <tr>
                                  <td height="95" align="center" valign="middle"><table width="85%" border="0" cellspacing="4" cellpadding="0">
                                     
                                      <tr>
                                        <td>用户名:</td>
                                        <td>
                                            <input type="text" name="name" size="15" value=""  maxlength="30">
                                            <input type="hidden" name="rname" size="15" value=""  maxlength="30">
                                        </td>
                                      </tr>
                                      <tr>
                                        <td>密&nbsp;&nbsp;码:</td>
                                        <td>
                                            <input type="password" name="password" value="" size=15  maxlength="30">
                                            
                                        </td>
                                      </tr>
                                    </table></td>
                                </tr>
                                <tr>
                                  <td align="center" valign="top"><table width="80%" border="0" cellspacing="0" cellpadding="0">
                                      <tr>
                                        <td width="64%">&nbsp;</td>
                                        <td width="36%"><input type="image" src="images/company/gzdx/denglu.gif" width="54" height="19"></td>
                                      </tr>
                                    </table></td>
                                </tr>
                              </table></td>
                            <td width="8">&nbsp;</td>
                          </tr>
                          <tr align="center"> 
                            <td colspan="3">建议使用IE6.0版本,<a href="http://download.microsoft.com/download/ie6sp1/finrel/6_sp1/W98NT42KMeXP/CN/ie6setup.exe" class="link1" alt="开始下载IE6.0安装程序">在此下载</a><br>
                            </span></td>
                          </tr>
                        </table></td>
                      <td width="10" align="left" valign="top">&nbsp;</td>
                    </tr>
                  </table></td>
              </tr>
            </table></td>
        </tr>
        
      </table>
      </form>
    </center>
    </body>
    </html>
      

  3.   

    给你一个很简单的。表结构:(表名users)用户名(id),密码(password):(都是varchar)我用的是数据库sql2000。
    登陆:(login.jsp)
    <%@ page contentType = "text/html;charset = GB2312" %>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>登录页面</title>
    </head>
    <body>
    <form action="validate.jsp" method=post>
              <p align=left><font color=#666666>用 户</font> 
                <input maxlength=10 name="id" size=10><font color=#666666>密 码</font> 
                <input maxlength=10 name="password" size=10 type=password>
                <input id=submit13 name=submit1 type=submit value=登录>
              </p>
            </form>
    </body>
    </html>
    判断页面:(validate.jsp)
    <%@ page import="java.sql.*"
       contentType="text/html; charset=GB2312" %>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>Validate</title>
    </head>
    <body>
         <%
           String name=new String();
           name=new String((request.getParameter("id")).getBytes("ISO8859-1"),"gb2312");
           session.putValue("thename",name);
         %>
         <%
                  int n;
                  String temp1=new String();
                  String temp2=new String();
                  temp1 = new String((request.getParameter("id")).getBytes("ISO8859-1"),"gb2312");
                  temp2 = request.getParameter("password");
                  n = temp1.length()*temp2.length();
                  if (n==0) {
                  %>
                      <jsp:forward page="login.jsp" />
                  <%
                  }
                  else{
                  String url=new String();
                  url="jdbc:microsoft:sqlserver://202.119.121.226:1433;DatabaseName=tzku";
                  String ur=new String();
                  ur="sa";
                  String pw=new String();
                  pw="12345";
                  Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
                  Connection con=DriverManager.getConnection(url,ur,pw);
                  Statement stmt=con.createStatement();
                  String SQL=new String();
                  SQL = "SELECT * FROM users WHERE id='"+temp1+"'and password='"+temp2+"'";
                  ResultSet rs = stmt.executeQuery(SQL);
                  if(rs.next()) {
                     String username=new String((rs.getString("id")).getBytes("ISO8859-1"),"gb2312");
                     if(username.equals("admin")) {
                     %>
                       <jsp:forward page="adminIndex.jsp" />
                     <%
                     rs.close();
                     }
                     else{
                       %>
                       <jsp:forward page="mainchoose.jsp" />
                       <%
                     }
                  }
                  else {
                    %>
                      <jsp:forward page="LoginAgain.jsp" />
                    <%
                  }
                  stmt.close();
                  con.close();
                  }
          %>
    </body>
    </html>