<%@ page language="java" contentType="text/html;
charset=utf-8" pageEncoding="utf-8"
%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>students</title>
</head>
<body>
<%
String driverClass="com.mysql.cj.jdbc.Driver";
Class.forName(driverClass);
String url="jdbc:mysql://localhost:3306/test";
String username="root";
String password="123456";
Connection conn=DriverManager.getConnection(url, username, password);
Statement stmt=conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from students");
if(rs.next()){
out.println(rs.getString("name"));
}else{
out.println("登录失败");
response.setHeader("refresh","5;url=login.jsp");
}
rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
要在tomcat下的lib里放入自己的jdbc驱动