jsp 常常遇到的问题
2021-01-16 05:11
标签:标识 out NPU extc name mys 文件配置 pass app jsp 常常遇到的问题 标签:标识 out NPU extc name mys 文件配置 pass app 原文地址:https://www.cnblogs.com/zhenqk/p/13381824.html1.数据库连接文件配置问题
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 的配置文件
3. Servlet 跳转的路径问题
response.sendRedirect("getusers");//http://localhost:8080/szu/getusers
// response.sendRedirect("/getusers"); http://localhost:8080/getusers