Servlet代码@WebServlet("/UpdateStudent")
public class UpdateStudent extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String idStr = request.getParameter("id");
if(idStr != null && !idStr.equals("")){
int id = Integer.valueOf(idStr);
AdminDao dao = new AdminDao();
Student stu = dao.selectStudentById(id);
request.setAttribute("stu", stu);
}
request.getRequestDispatcher("/UpdateStudent.jsp").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String sname = request.getParameter("sname");
String password = request.getParameter("password");
String sno = request.getParameter("sno");
String sex = request.getParameter("sex");
String major = request.getParameter("major");
String grade = request.getParameter("grade");
Student student = new Student();
student.setSname(new String(sname.getBytes("ISO-8859-1"),"UTF-8"));
student.setPassword(password);
student.setSno(sno);
student.setSex(new String(sex.getBytes("ISO-8859-1"),"UTF-8"));
student.setMajor(new String(major.getBytes("ISO-8859-1"),"UTF-8"));
student.setGrade(new String(grade.getBytes("ISO-8859-1"),"UTF-8"));
AdminDao dao = new AdminDao();
dao.UpdateStudent(student);
request.getRequestDispatcher("/Information").forward(request, response);
}
添加回答
举报
0/150
提交
取消