SignAction.java
上传用户:jishiqi_cj
上传日期:2022-08-08
资源大小:24765k
文件大小:2k
源码类别:

Java编程

开发平台:

Java

  1. package StudyBbs;
  2. import javax.servlet.http.HttpServletRequest;
  3. import javax.servlet.http.HttpServletResponse;
  4. import org.apache.struts.action.Action;
  5. import org.apache.struts.action.ActionForm;
  6. import org.apache.struts.action.ActionForward;
  7. import org.apache.struts.action.ActionMapping;
  8. import org.apache.struts.action.ActionMessage;
  9. import org.apache.struts.action.ActionMessages;
  10. import javax.servlet.ServletContext;
  11. import javax.sql.DataSource;
  12. import java.sql.Connection;
  13. public final class SignAction extends Action{  
  14. public ActionForward execute(
  15. ActionMapping mapping,
  16. ActionForm form,
  17. HttpServletRequest request,  
  18. HttpServletResponse response) throws Exception {
  19.     UserForm userform = (UserForm) form;         
  20. String username = userform.getUsername();
  21. String password = userform.getPassword();
  22. String nickname = userform.getNickname();
  23. String sex = userform.getSex();
  24. String birthyear = userform.getBirthyear();
  25. String birthmonth = userform.getBirthmonth();
  26. String birthday = userform.getBirthday();
  27. String email = userform.getEmail();
  28. String mobile = userform.getMobile();
  29. String signiture = userform.getSigniture();
  30.     ServletContext context = servlet.getServletContext();
  31. DataSource dataSource = (DataSource)context.getAttribute(Constants.DATASOURCE_KEY);
  32.         DB db = new DB(dataSource);
  33.         User user=new User();
  34.         user.setUsername(username);
  35.         user.setPassword(password);
  36.         user.setNickname(nickname);
  37.         user.setSex(sex);
  38.         user.setBirthyear(birthyear);
  39.         user.setBirthmonth(birthmonth);
  40.         user.setBirthday(birthday); 
  41.         user.setEmail(email);
  42.         user.setMobile(mobile);
  43.         user.setSigniture(signiture);
  44. String PageForward;
  45. ActionMessages errors = new ActionMessages();
  46.         
  47.         if (!username.equals("guest") && user.Insert(db)) {
  48. PageForward="toLogin";  //新用户注册成功
  49.         }
  50.         else{                       //新用户注册失败
  51.             errors.add(ActionMessages.GLOBAL_MESSAGE,
  52.                            new ActionMessage("errors.registFail"));
  53. if (!errors.isEmpty()) {
  54. saveErrors(request, errors);
  55.   PageForward="toWrong";
  56.         } 
  57.            
  58. db.close();
  59.    return  mapping.findForward(PageForward);  
  60.   }
  61. }