package servlet; import dao.ScoreD; import dao.StudentD; 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 java.io.IOException; import java.io.PrintWriter; @WebServlet("/add_student") public class add_student extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doGet(request, response); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); response.setCharacterEncoding("utf-8"); request.setCharacterEncoding("utf-8"); PrintWriter out = response.getWriter(); StudentD studentD = new StudentD(); ScoreD scoreD = new ScoreD(); String id = request.getParameter("id"); String name = request.getParameter("name"); String sex = request.getParameter("sex"); String major = request.getParameter("major"); String school_date = request.getParameter("school_date"); try { studentD.insertStudent(id, name, sex, school_date, major); scoreD.insertScore(id); } catch (Exception e){ out.print(e); } response.sendRedirect("one_page_student"); } } 数据结构
时间: 2024-04-28 15:21:01 浏览: 127
d-scored-puncher的开源项目学习与复制.zip
这段代码是一个 Java Servlet,用于添加学生信息和成绩信息到数据库中。它使用了两个 DAO(Data Access Object)类:StudentD 和 ScoreD,分别用于将学生信息和成绩信息插入到数据库中。在 doPost 和 doGet 方法中,先获取请求中的参数值,然后调用 StudentD 和 ScoreD 的插入方法将数据插入数据库中。如果出现异常,则将异常信息输出到页面上。最后,重定向到 one_page_student 页面。
阅读全文