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

Internet/IE编程

开发平台:

Java

  1. package com.xdf.exams.web.action;
  2. import javax.servlet.http.HttpServletRequest;
  3. import javax.servlet.http.HttpServletResponse;
  4. import org.apache.struts.action.ActionForm;
  5. import org.apache.struts.action.ActionForward;
  6. import org.apache.struts.action.ActionMapping;
  7. import com.xdf.exams.bean.Student;
  8. import com.xdf.exams.bo.BOFactory;
  9. import com.xdf.exams.bo.IStudentService;
  10. import com.xdf.exams.web.form.StudentForm;
  11. /** 
  12.  * MyEclipse Struts
  13.  * Creation date: 04-05-2007
  14.  * 
  15.  * XDoclet definition:
  16.  * @struts.action validate="true"
  17.  */
  18. public class RegistAction extends BaseDispatchAction {
  19. /** 
  20.  * Method execute
  21.  * @param mapping
  22.  * @param form
  23.  * @param request
  24.  * @param response
  25.  * @return ActionForward
  26.  */
  27. public ActionForward regist(ActionMapping mapping, ActionForm form,
  28. HttpServletRequest request, HttpServletResponse response) {
  29. this.saveToken(request);
  30. return mapping.findForward("regist");
  31. }
  32. public ActionForward registdo(ActionMapping mapping, ActionForm form,
  33. HttpServletRequest request, HttpServletResponse response) {
  34. StudentForm studentForm = (StudentForm)form;
  35. ActionForward forward = null;
  36. if(this.isTokenValid(request)) {
  37. IStudentService ser = BOFactory.getStudentService();
  38. try {
  39. if(ser.checkStudentNameExists(studentForm.getUsername(),null)) {
  40. request.setAttribute("message","用户名已经存在");
  41. forward = mapping.findForward("regist");
  42. }else {
  43. Student s = new Student();
  44. s.setAddress(studentForm.getAddress());
  45. s.setEmail(studentForm.getEmail());
  46. s.setName(studentForm.getName());
  47. s.setPassword(studentForm.getNewpassword());
  48. s.setSex(studentForm.getSex());
  49. s.setUsername(studentForm.getUsername());
  50. ser.addStudent(s);
  51. request.setAttribute("message","增加成功");
  52. forward = mapping.findForward("registmessage");
  53. this.resetToken(request);
  54. }
  55. } catch (RuntimeException e) {
  56. e.printStackTrace();
  57. request.setAttribute("message","增加失败");
  58. forward = mapping.findForward("regist");
  59. }
  60. }else {
  61. request.setAttribute("message","请不要重复提交");
  62. forward = mapping.findForward("registmessage");
  63. }
  64. return forward;
  65. }
  66. }