<%@ page import="com.user" %>
<%@ page import="javax.print.DocFlavor" %>
<%@ page import="com.mysql.jdbc.Connection" %>
<%@ page import="com.mysql.jdbc.Driver" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Statement" %>
<%--
Created by IntelliJ IDEA.
User: 和
Date: 2020/9/29
Time: 14:12
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="textml;charset=UTF-8" language="java" %>
<jsp:useBean id="user" class="com.user" ></jsp:useBean>
<jsp:setProperty name="user" property="*"></jsp:setProperty>
<%
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://127.0.0.1:3306/book?user=root&password=root";
java.sql.Connection connection = DriverManager.getConnection(url);
String sql = "insert into user (username,password,gender,age) values('"+user.getUsername()+"','"+user.getPassword()+"',1,23)";
Statement stat = connection.createStatement();
int count= stat.executeUpdate(sql);
if(count ==0)
{
out.print("注册失败");
}
else
{
out.print("注册成功");
}
%>
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/db71f4f29277b4ca80c8c1280d83342c.png#pic_center)
<form method="post" action="regjster.jsp">
用户名:<input type="text" name="username"><br>
密码: <input type="text" name="password"><br>
性别: <input type="text" name="gender"><br>
年龄: <input type="text" name="age"><br>
<button type="submit">注册</button>
</form>
package user;
public class user {
private String username;
private String name;
private int age;
private String password;
public String getUsername(){
return username;}
public void setUsername(String username) {
this.username = username;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/1b083cb53fbc1fee1ad1502027748daf.png#pic_center)