源码如下
index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
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>登陆页面</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">
-->
  </head>
  
  <body>
  <center><h1>欢迎来到管理登陆界面</h1></center>
    <div  align="center" style=" margin-top:100px;">
<form id="form" name="form" method="post" action="login.jsp">
<p>
<label >用户ID:
<input name="username" type="text" id="username" size="15" /></label>
</p>
<p>
<label>密&nbsp;&nbsp;码:
<input name="password" type="password" id="password" size="15" /></label>
</p>
  <label><input name="" type="submit" value="登陆" /></label>
</form>
</div>
  </body>
</html>login.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="java.sql.*"%>
<%
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>登陆页面</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">
-->  </head>
  
  <body>
    <%
    String userid = new String(request.getParameter("username").getBytes("ISO-8859-1"),"GBK"); 
    String password = new String(request.getParameter("password").getBytes("ISO-8859-1"),"GBK"); 
    if ( userid == "" || userid == null || userid.length()>20 || password == "" || password == null || password.length()>20 )
     {
      try
      {   
      response.sendRedirect ( "wrong.jsp?wrongid=1" );
      
      } catch ( Exception e )
      {
      }
     }      
    else{
    Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
conn =DriverManager.getConnection("jdbc:odbc:student");
stmt = conn.createStatement();     
String sql="SELECT * FROM denglu where id="+userid+" and pw="+password;
    if (stmt.execute(sql)) {
        rs = stmt.getResultSet();
        while(rs.next()){
        out.println("登陆成功!<br />");
            out.println("欢迎您:"+rs.getString("name")); 
            }  
    }   
        conn.close();
}
catch (SQLException ex){
    response.sendRedirect ( "wrong.jsp?wrongid=2" );
} catch (InstantiationException e) {
response.sendRedirect ( "wrong.jsp?wrongid=2" );
} catch (IllegalAccessException e) {
response.sendRedirect ( "wrong.jsp?wrongid=2" );
} catch (ClassNotFoundException e) {
response.sendRedirect ( "wrong.jsp?wrongid=2" );
}
finally {
    if (rs != null) {
        try {
            rs.close();
        } catch (SQLException sqlEx) { } // ignore
        rs = null;
    }
    if (stmt != null) {
        try {
            stmt.close();
        } catch (SQLException sqlEx) { } // ignore
        stmt = null;
    }
}
    }
     %>
  </body>
</html>
 
wrong.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
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 'wrong.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">
-->  </head>
  
  <body>
 <% 
  String n = request.getParameter("wrongid");
  if(n.equals("1")){
  out.println("1.您没输入ID或密码。<br />2.ID和密码不能超过20字符<br />");
  out.println("<a href=\"index.jsp\">点此重新登陆</a>");
  }
  else if(n.equals("2")){
  out.println("Sorry,登陆失败。<br />");
  out.println("您输入的用户ID或密码不对哦。<br />");
  out.println("<a href=\"index.jsp\">点此重新登陆</a>");
  }
  else{
  out.println("你又在干坏事拉!");
  }
 %>   
  </body>
</html>Access数据库
编号     id         pw
1       admin      123输入账号admin 密码123登不进去, 为什么求解
Sorry,登陆失败。
您输入的用户ID或密码不对哦。

解决方案 »

  1.   

    catch (SQLException ex){
        System.out.println("SQLException ") ;
        response.sendRedirect ( "wrong.jsp?wrongid=2" );
    } catch (InstantiationException e) {
        System.out.println("InstantiationException ") ;
        response.sendRedirect ( "wrong.jsp?wrongid=2" );
    } catch (IllegalAccessException e) {
        System.out.println("IllegalAccessException ") ;
        response.sendRedirect ( "wrong.jsp?wrongid=2" );
    } catch (ClassNotFoundException e) {
        System.out.println("ClassNotFoundException ") ;
       response.sendRedirect ( "wrong.jsp?wrongid=2" );
    }
    加上调试信息 ,看看你的报什么异常了 ,你都捕捉了异常,应该在后台或者日志中写入异常信息,否则怎么调试啊
      

  2.   

    你的用户Id不应该从request里面取吧?
      

  3.   

    每一个catch中 ,都打印一些信息出来,看看是报什么异常
    catch(...  e){
       e.printStackTrace() ;
    }上面我已经写了 ,你只用把2楼上的内容替换掉你的login.jsp中对应的,然后运行你的登录页面,然后看看后台打印了什么就可以了 
      

  4.   

    如下,输出错误堆栈信息
    catch (SQLException ex){
      e.printStackTrace();
      response.sendRedirect ( "wrong.jsp?wrongid=2" );
    } catch (InstantiationException e) {
      e.printStackTrace();
      response.sendRedirect ( "wrong.jsp?wrongid=2" );
    } catch (IllegalAccessException e) {
      e.printStackTrace();
      response.sendRedirect ( "wrong.jsp?wrongid=2" );
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
      response.sendRedirect ( "wrong.jsp?wrongid=2" );
    }
      

  5.   

    看看你的tomcat打印了些什么东西,如果你的程序是用myeclipse这样的IDE编写的,可以设置断点进行debug
      

  6.   

    org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 56 in the jsp file: /login.jsp
    Syntax error, insert "AssignmentOperator Expression" to complete Assignment
    53:          while(rs.next()){
    54:          out.println("鐧婚檰鎴愬姛锛�br />");
    55:              out.println("娆㈣繋鎮細"+rs.getString("name")); 
    56:  response
    57:              }  
    58:      }   
    59:          conn.close();
    An error occurred at line: 56 in the jsp file: /login.jsp
    Syntax error, insert ";" to complete Statement
    53:          while(rs.next()){
    54:          out.println("鐧婚檰鎴愬姛锛�br />");
    55:              out.println("娆㈣繋鎮細"+rs.getString("name")); 
    56:  response
    57:              }  
    58:      }   
    59:          conn.close();
    Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:102)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:331)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:469)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    note The full stack trace of the root cause is available in the Apache Tomcat/7.0.27 logs.
      

  7.   

    你的代码我没看完啊,但是我看到你的SQL的时候就觉得有问题
    首先:String userid = new String(request.getParameter("username").getBytes("ISO-8859-1"),"GBK");
    这是你取的用户名,虽然你用的变量名是userid,但是他的值是用户名,然后你的SQL
    String sql="SELECT * FROM denglu where id="+userid+" and pw="+password;
    却是在用id和密码去匹配,你用用户名怎么去匹配id??能登录才有鬼
      

  8.   

    login.jsp
    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
    <%@ page import="java.sql.*"%>
    <%
    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>登陆页面</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">
     -->   </head>
        
      <body>
       <%
       String userid = new String(request.getParameter("username").getBytes("ISO-8859-1"),"GBK");  
      String password = new String(request.getParameter("password").getBytes("ISO-8859-1"),"GBK");  
      if ( userid == "" || userid == null || userid.length()>20 || password == "" || password == null || password.length()>20 )
       {
       try
       {   
      response.sendRedirect ( "wrong.jsp?wrongid=1" );
         
      } catch ( Exception e )
       {
       }
       }   
      else{
       Connection conn = null;
     Statement stmt = null;
     ResultSet rs = null;
     try {
     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
     conn =DriverManager.getConnection("jdbc:odbc:student");
     stmt = conn.createStatement();   
    String sql="SELECT * FROM denglu where id="+userid+" and pw="+password;
     if (stmt.execute(sql)) {
     rs = stmt.getResultSet();
     while(rs.next()){
     out.println("登陆成功!<br />");
     out.println("欢迎您:"+rs.getString("name"));  
    }   
    }   
    conn.close();
     }
     catch (SQLException ex){
     response.sendRedirect ( "wrong.jsp?wrongid=2" );
     } catch (InstantiationException e) {
     response.sendRedirect ( "wrong.jsp?wrongid=2" );
     } catch (IllegalAccessException e) {
     response.sendRedirect ( "wrong.jsp?wrongid=2" );
     } catch (ClassNotFoundException e) {
     response.sendRedirect ( "wrong.jsp?wrongid=2" );
     }
     finally {
     if (rs != null) {
     try {
     rs.close();
     } catch (SQLException sqlEx) { } // ignore
     rs = null;
     }
     if (stmt != null) {
     try {
     stmt.close();
     } catch (SQLException sqlEx) { } // ignore
     stmt = null;
     }
     }
       }
       %>
       </body>
    </html>
      

  9.   

    我的数据库中id就是对应的用户名啊。 数据库在1L最后。。 是匹配的啊。
      

  10.   

    哦,不好意思,我看错了,你表结构的用户名就是用的ID,我面壁思过。
    建议你把sql打印出来看一下,然后把打印出来的SQL贴到数据库里去执行一下
    String sql="SELECT * FROM denglu where id='"+userid+"' and pw='"+password+"'";
    把SQL改成上面的看看,id和password都是字符串
      

  11.   

    String userid = new String(request.getParameter("username").getBytes("ISO-8859-1"),"GBK");   
      String password = new String(request.getParameter("password").getBytes("ISO-8859-1"),"GBK");   
      if ( userid == "" || userid == null || userid.length()>20 || password == "" || password == null || password.length()>20 )修改成 :String userid = new String(request.getParameter("username").getBytes("ISO-8859-1"),"GBK");   
      String password = new String(request.getParameter("password").getBytes("ISO-8859-1"),"GBK");   
    System.out.println("参数:" + userid  + "-----" + password) ; //看看打印出来的是什么
      if ( userid == null  || userid == ""  || userid.length()>20 || password == null || password == "" ||  password.length()>20 )
      

  12.   

    这样输出是不行啊,因为后面它会自动跳转到wrong.jsp去。
      

  13.   

    嗯,改完之后出来新问题了,如果输入admin  123的话还是提示您输入的密码不对,但随便输入个其他的,比如账号asd密码ddf就出现空白界面
      
      

  14.   

    把SQL打印出来看看就全明白了
    String sql="SELECT * FROM denglu where id='"+userid+"' and pw='"+password+"'";
    下面加一句System.out.println(sql);
    这个打印不是出现在页面上的,是日志文件里啊
      

  15.   

    直接进你的wrong.jsp肯定是条件没有过,所以你String userid = new String(request.getParameter("username").getBytes("ISO-8859-1"),"GBK");   
      String password = new String(request.getParameter("password").getBytes("ISO-8859-1"),"GBK");   
    看下你取出的结果是啥样子的。我觉得可能和编码有关系,因为乱码了
      

  16.   


    1.但是如果输入admin  123的话还是提示您输入的密码不对,贴出控制台输出的错误信息
    2.这样修改,你随便输入的用户名密码就不会白了
    if(rs.next()){
     out.println("登陆成功!<br />");
     out.println("欢迎您:"+rs.getString("name"));  
    }else{
     response.sendRedirect ( "wrong.jsp?wrongid=2" );
    }
      

  17.   

    tomcat安装目录下面有个logs文件夹,按名称排正序,最后有个以你tomcat启动那天的日期加上stdout命名的文件就是了
      

  18.   

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
    conn =DriverManager.getConnection("jdbc:odbc:student");
    stmt = conn.createStatement();   
    String sql="SELECT * FROM denglu where id="+userid+" and pw="+password;中的
    conn=DriverManager.getConnection("jdbc:odbc:driver={Microsoft Access Driver (*.MDB)};DBQ=access数据库文件存放的目录");
      

  19.   

    SELECT * FROM denglu where id='admin' and pw='123'到查询分析器中可以查处结果嘛 ?你收一下你的邮件 
      

  20.   

    真的不行啊,加上else一样会出现空白页面
      

  21.   

    不是说了不要看页面  去看日志吗   System.out.println();这方法不是在页面输出的,是输出到控制台(如果你是在myeclipse里启动tomcat的)或日志文件的