登录页面
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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>登录信息</title>
</head>
<body>
<form action="check.jsp">
<input type="text" name="stuAccount" value=""/><br/>
<input type="password" name="stuPwd" value=""/><br/>
<input type="submit" value="登录"/>
<input type="reset" value="重置"/>
</form>
</body>
</html>
连接数据库
<%@page import="java.sql.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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>学员登录信息</title>
</head>
<body>
<h1>学院信息</h1>
<%
request.setCharacterEncoding("UTF-8"); // 设置参数字符集
String stuAccount = request.getParameter("stuAccount");
String stuPwd = request.getParameter("stuPwd");
// 获取数据库连接
Class.forName("com.mysql.jdbc.Driver");
Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost:3306/teach?useUnicode=true&characterEncoding=utf8","root","");
PreparedStatement pst = conn.prepareStatement("select name, code from t_student where stuAccount=? and stuPwd=?");
pst.setString(1, stuAccount);
pst.setString(2, stuPwd);
ResultSet rs = pst.executeQuery();
String stuName = "";
String stuCode = "";
boolean flag = false;
while (rs.next()) {
stuName = rs.getString("name");
stuCode = rs.getString("code");
flag = true;
}
if(flag) {
out.println("姓名: " + stuName + " 学号: " + stuCode);
} else {
out.println("没有找到相关数据!请<a href='login.jsp'>重新登录</a>");
}
pst.close();
conn.close();
%>
</body>
</html>
JSP—一个简单的登录界面
最新推荐文章于 2024-06-07 10:36:57 发布