jsp 常常遇到的问题

1.数据库连接文件配置问题

1. resources/jdbc.properties

driver=com.mysql.jdbc.Driver
url=jdbc:mysql://127.0.0.1:3306/kdb1
username=root
password=root

2. dbConn.java

public class dbConn {
    public static Connection getConn() {
        Connection con = null;
        try {
            DataSource source1;
            Properties p = new Properties();
            String path = Thread.currentThread().getContextClassLoader().getResource  ("jdbc.properties").getPath();
            p.load(new FileInputStream(path));
            String driver = p.getProperty("driver");
            System.out.println(driver);
            String url = p.getProperty("url");
            String username = p.getProperty("username");
            String passwd = p.getProperty("password");
            Class.forName(driver); // 加载驱动程序

            con = DriverManager.getConnection(url, username, passwd);
            return con;
        } catch (ClassNotFoundException | FileNotFoundException e) {
            System.out.println("加载驱动程序错误" + e.getMessage());
        } catch (IOException e) {
            e.printStackTrace();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;

    }
}

2. web.xml 的配置文件

  
    index.jsp
  


  
    LoginServlet   
    cn.ccut.servlet.LoServlet   
  

  
    LoginServlet    
    /userlogin  
  

3. Servlet 跳转的路径问题

     response.sendRedirect("getusers");//http://localhost:8080/szu/getusers
       //     response.sendRedirect("/getusers");       http://localhost:8080/getusers


你可能感兴趣的:(jsp 常常遇到的问题)