标签:标识 out NPU extc name mys 文件配置 pass app
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://127.0.0.1:3306/kdb1
username=root
password=root
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;
}
}
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>LoginServlet</servlet-name> <!-- 3 标识名,可随便起对应的 -->
<servlet-class>cn.ccut.servlet.LoServlet</servlet-class> <!-- 4 对应本项目 Servlet -->
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name> <!-- 2 标识名 可随便起 -->
<url-pattern>/userlogin</url-pattern> <!-- 1 访问的url ,http://127.0.0.1/userlogin -->
</servlet-mapping>
response.sendRedirect("getusers");//http://localhost:8080/szu/getusers
// response.sendRedirect("/getusers"); http://localhost:8080/getusers
标签:标识 out NPU extc name mys 文件配置 pass app
原文地址:https://www.cnblogs.com/zhenqk/p/13381824.html