package org.student.servlet; 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 org.student.service.StudentService; import ogr.student.entity.Student; /** * Servlet implementation class AddStudentServlet */ @WebServlet("/AddStudentServlet") public class AddStudentServlet extends HttpServlet { private static final long serialVersionUID = 1L; public AddStudentServlet() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); int num = Integer.parseInt(request.getParameter("snum")); String name=request.getParameter("sname"); int age = Integer.parseInt(request.getParameter("sage")); String adress = request.getParameter("sadress"); Student student = new Student(num,age,name,adress); StudentService stu=new StudentService(); boolean rescult = stu.addStudent(student); response.setCharacterEncoding("utf-8"); response.setContentType("text/html; charset=utf-8"); PrintWriter out = response.getWriter(); if(rescult) { out.println("增加成功"); }else { out.println("增加失败"); } } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } }