StudentInfoAction.java
上传用户:nbxinmin
上传日期:2021-10-09
资源大小:46k
文件大小:3k
源码类别:

Internet/IE编程

开发平台:

Java

  1. package com.xdf.exams.web.action;
  2. import javax.servlet.http.HttpServletRequest;
  3. import javax.servlet.http.HttpServletResponse;
  4. import javax.servlet.http.HttpSession;
  5. import org.apache.struts.action.ActionForm;
  6. import org.apache.struts.action.ActionForward;
  7. import org.apache.struts.action.ActionMapping;
  8. import com.xdf.exams.bean.Student;
  9. import com.xdf.exams.bo.BOFactory;
  10. import com.xdf.exams.bo.ILogService;
  11. import com.xdf.exams.bo.IStudentService;
  12. import com.xdf.exams.web.form.StudentForm;
  13. /**
  14.  * MyEclipse Struts Creation date: 04-04-2007
  15.  * 
  16.  * XDoclet definition:
  17.  * 
  18.  * @struts.action path="/student/info/update" name="studentForm" scope="request"
  19.  *                validate="true"
  20.  */
  21. public class StudentInfoAction extends BaseDispatchAction {
  22. public ActionForward update(ActionMapping mapping, ActionForm form,
  23. HttpServletRequest request, HttpServletResponse response)
  24. throws Exception {
  25. StudentForm studentForm = (StudentForm) form;
  26. HttpSession session = request.getSession();
  27. Student s = (Student) session.getAttribute("student");
  28. if (s != null) {
  29. studentForm.setAddress(s.getAddress());
  30. studentForm.setEmail(s.getEmail());
  31. studentForm.setName(s.getName());
  32. studentForm.setSex(s.getSex());
  33. studentForm.setUsername(s.getUsername());
  34. studentForm.setStudentid(s.getStudentid());
  35. }
  36. return mapping.findForward("update");
  37. }
  38. public ActionForward updatedo(ActionMapping mapping, ActionForm form,
  39. HttpServletRequest request, HttpServletResponse response)
  40. throws Exception {
  41. StudentForm studentForm = (StudentForm) form;
  42. HttpSession session = request.getSession();
  43. Student s = (Student) session.getAttribute("student");
  44. if (s != null) {
  45. IStudentService sser = BOFactory.getStudentService();
  46. ILogService lser = BOFactory.getLogService();
  47. try {
  48. Student news = lser.studentlogin(s.getUsername(), studentForm
  49. .getOldpassword());
  50. if (news != null) {
  51. if (sser.checkStudentNameExists(studentForm.getUsername(),studentForm.getStudentid())) {
  52. request.setAttribute("message", "用户名已经存在");
  53. } else {
  54. news.setAddress(studentForm.getAddress());
  55. news.setEmail(studentForm.getEmail());
  56. news.setName(studentForm.getName());
  57. news.setPassword(studentForm.getNewpassword());
  58. news.setSex(studentForm.getSex());
  59. news.setUsername(studentForm.getUsername());
  60. sser.updateStudent(news);
  61. session.setAttribute("student", news);
  62. request.setAttribute("message", "修改成功");
  63. }
  64. } else {
  65. request.setAttribute("message", "旧密码输入错误");
  66. }
  67. } catch (RuntimeException e) {
  68. request.setAttribute("message", "修改失败");
  69. e.printStackTrace();
  70. }
  71. }
  72. return mapping.findForward("update");
  73. }
  74. }