html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>测试</title>
<script>
//function checkform(){
//var uValue = document.getElementById("teacher").value;
//if(uValue != "王建民"&&uValue != "刘立嘉"&&uValue != "刘丹"&&uValue != "杨子辉"&&uValue != "王学军")
//{
// return false;
//}
//else{
//}
//var pValue= document.getElementById("place").value;
//if(pValue != "基教"&&pValue != "一教"&&pValue != "二教"&&pValue != "三教")
//{
// return false;
// }
//else{
// }
//}
</script>
</head>
<body>
<form action = "shujuku.jsp" method = "post" onsubmit="return checkform()">
<table border="1px" align="center">
<tr>
<td>所学课程<input type="text" name="username" id = "user"></td><br>
</tr>
<tr>
<td>上课教师<input type="text" name="teacher" id = "teacher"></td><br>
</tr>
<tr>
<td>上课地点<input type = "text" name="classplace" id = "place"></td><br>
</tr>
<tr>
<td><input type = "submit" value="提交"></td>
</tr>
</table>
</form>
</body>
</html>
jsp
<%@ 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>SQLTest</title>
</head>
<body>
<li><p><b>第一个数:</b>
<%
String s=request.getParameter("user");
out.println(s);
%>
</p></li>
<li><p><b>第二个数:</b>
<%String name=new String(request.getParameter("teacher").getBytes("ISO-8859-1"),"UTF-8"); %>
<%out.println(name); %>
</p></li>
<li><p><b>第三个数:</b>
<%String place=new String(request.getParameter("classplace").getBytes("ISO-8859-1"),"UTF-8"); %>
<%out.println(place); %>
</p></li>
<%
Connection con;
Statement st;
ResultSet rs;
PreparedStatement stmt;
try{
Class.forName("com.mysql.cj.jdbc.Driver");//获取数据库连对象
}catch(Exception e){
out.println("忘记把mySQL数据库的jdbc数据库驱动程序复制到jdk的扩展目录中 ");
}
try{
String url="jdbc:mysql://localhost/sakura?serverTimezone=GMT%2B8&useSSL=false"; //数据库连接字
String name1="root";
String pass="sakura123xxg";
con = DriverManager.getConnection(url,name1,pass);//加载并注册驱动程序
st = con.createStatement();
String sql = "insert into test(class,teacher,place) values (?,?,?)";
stmt = con.prepareStatement(sql);
stmt.setString(1,"1");
stmt.setString(2,name);
stmt.setString(3,place);
int n = stmt.executeUpdate();
rs = st.executeQuery("select * from test");
con.close();
}catch(SQLException e){
out.print(e);
}
%>
</body>
</html>