本帖最后由 C_way 于 2012-06-20 14:35:17 编辑

解决方案 »

  1.   

    这个jar的版本太低了,换个5.0的看看吧!有可能是这问题!
      

  2.   

    mysql-connector-java-3.1.12-bin.jar还行啊 ,
    1、你看看后台报错了没有 ?2、还有就是你查看一些你的业务逻辑是否有问题 ?3、在你的业务逻辑代码中多加一些调试信息 ,查看后台 ,看看程序运行到哪里 ,容易找出问题所在 ;
      

  3.   

    我贴上代码吧。还有就是我没连数据库前是能跳转页面的,写上连接数据库的代码就不行了logcl是业务逻辑层package com.login;import javax.servlet.http.*;
    import java.sql.*;
    import java.io.*;
    public class LoginCl extends HttpServlet {    public void doGet(HttpServletRequest req, HttpServletResponse res) {
        
         Connection cc = null;
         Statement sm = null;
         ResultSet rs = null;     try {
         String u = req.getParameter("username");
         String p = req.getParameter("passwd");
        
     
          Class.forName("com.mysql.jdbc.Driver");
    cc = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306;databaseName=sqdb", "root", "1");
          sm = cc.createStatement();
          rs = sm.executeQuery("select top 1 * from users where username='"+u+"' and passwd='"+p+"'");
        
         if (rs.next()) {
        
         HttpSession hs = req.getSession(true);
         hs.setMaxInactiveInterval(20);
           hs.setAttribute("name", u);
        
         res.sendRedirect("wel?un="+u+"&pw="+p);
        
         }
        
         else {
         res.sendRedirect("login");
         }
        }
        
        catch (Exception ex) {
         ex.printStackTrace();
        }
        finally {
    try {
    if (rs !=null) {
    rs.close();
    }
    if (sm !=null) {
    sm.close();
    }
    if (cc != null) {
    cc.close();
    }
    }
    catch (Exception ex) {
    ex.printStackTrace();
    }
             }
        } 
        
        public void doPost(HttpServletRequest req, HttpServletResponse res) {
         this.doGet(req, res);
        }
    }
      

  4.   

    jdbc:mysql://127.0.0.1:3306;databaseName=sqdb
    把这个换成:
    jdbc:mysql://127.0.0.1:3306/sqdb
      

  5.   

    应该不是jar包问题,jar包版本还可以。报什么错误贴出来
      

  6.   

    package com.login;import javax.servlet.http.*;
    import java.sql.*;
    import javax.servlet.* ;
    import java.io.*;
    public class LoginCl extends HttpServlet {  public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{
      
      Connection cc = null;
      Statement sm = null;
      ResultSet rs = null;

      try {
      String u = req.getParameter("username");
      String p = req.getParameter("passwd");
      
      
      Class.forName("com.mysql.jdbc.Driver");
    cc = DriverManager.getConnection("jdbc:mysql://localhost:3306/=sqdb", "root", "1");
      sm = cc.createStatement();
      rs = sm.executeQuery("select  * from users where username='"+u+"' and passwd='"+p+"'");
      System.out.println("执行查询,获取校验结果...") ;
      if (rs.next()) {
      
    HttpSession hs = req.getSession(true);
       //hs.setMaxInactiveInterval(20);
       hs.setAttribute("name", u);
        System.out.println("执行重定向到wel...") ;
       res.sendRedirect("wel?un="+u+"&pw="+p);
      
      }else {
        System.out.println("执行重定向到login...") ;
       res.sendRedirect("login");
      }
    }catch (Exception ex) {
       ex.printStackTrace();
      }finally {
    try {
    if (rs !=null) {
    rs.close();
    }
    if (sm !=null) {
    sm.close();
    }
    if (cc != null  && !cc.isClosed()) {
    cc.close();
    }
    }catch (Exception ex) {
    ex.printStackTrace();
    }
     }
      }  
      
      public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
       this.doGet(req, res);
      }
    }
      

  7.   

    jar包应该没有问题的 ,你看看tomcat的后台,打印 那些信息 ,还有是否有异常信息...
      

  8.   

    = =,你打开mysql看看能不能打开,我以前用什么360之类的优化过,结果mysql服务就时不时的开不开
      

  9.   

    select那就错了,mysql不支持top,用selcet * from users where ……后面加上这个limit 1;只取一条符合查询条件的,如果是limit m,n 就是从m条开始(默认m为0)查找,取1条;jar包扔到tomcat的lib下之后,再配置一下tomcat下的conf里的context.xml
    <Resource name="jdbc/mysql" auth="Container" type="javax.sql.DataSource" 
         maxActive="100" maxIdle="30" maxWait="10000" username="root" password="root"
         driverClassName="com.sql.jdbc.Driver" url="jdbc:mysql://locolhost:3306/lhdb" />
    放到context标签里,里面意思你能看懂,然后在自己的配置文件里面把这个连接源配上就ok了
    <Resource name="jdbc/mysql" auth="Container" type="javax.sql.DataSource" 
         maxActive="100" maxIdle="30" maxWait="10000" username="root" password="root"
         driverClassName="com.sql.jdbc.Driver" url="jdbc:mysql://locolhost:3306/lhdb" />建议还是用startup启动tomcat,这样有助于看到控制台信息,不少错误可以排查
      

  10.   

    <resource-ref>
    <description> DB Connection </description>
    <res-ref-name>jdbc/mysql</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>不好意思 浏览器不给力 没复制上 web.xml里配置的内容,如上