整体的目录结构
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/1bea83cb3d886b878330ac36d192c853.png)
我们从上向下依次写代码
controller(Servlet文件)
package com.sz.controller;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.sz.entity.User;
import com.sz.service.UserService;
import com.sz.service.Impl.UserServiceImpl;
@WebServlet("/UserSaveController")
public class UserSaveController extends HttpServlet {
private static final long serialVersionUID = 1L;
public UserSaveController() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("text/html");
String name = request.getParameter("uname");
int age = Integer.parseInt(request.getParameter("age"));
String birth = request.getParameter("birth");
double salary = Double.parseDouble(request.getParameter("salary"));
UserService service = new UserServiceImpl();
PrintWriter pw = response.getWriter();
User u = new User(0,name,age,birth,salary);
if(service.saveUser(u)) {
pw.print("<h1>用户注册成功</h1>"