以下是一个简单的JSP表单,用于学生登陆:
```
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
学生登陆
学生登陆
```
在表单中,使用了POST方法提交数据,并将数据提交到login.jsp页面进行处理。
下面是login.jsp页面的代码,用于验证学生登陆信息:
```
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
学生登陆结果
学生登陆结果
<%
String id = request.getParameter("id");
String name = request.getParameter("name");
String message = "";
// 连接数据库
String url = "jdbc:mysql://localhost:3306/test";
String user = "root";
String password = "123456";
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(url, user, password);
// 执行SQL语句
String sql = "SELECT * FROM students WHERE id=? AND name=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, id);
pstmt.setString(2, name);
rs = pstmt.executeQuery();
// 处理查询结果
if (rs.next()) {
message = "登陆成功";
} else {
message = "登陆失败";
}
} catch (Exception e) {
e.printStackTrace();
} finally {
// 关闭数据库连接
try