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

Java编程

开发平台:

Java

  1. package classmate;
  2. import org.apache.struts.action.Action;
  3. import org.apache.struts.action.ActionForm;
  4. import org.apache.struts.action.ActionForward;
  5. import org.apache.struts.action.ActionMapping;
  6. import org.apache.struts.action.ActionMessages;
  7. import org.apache.struts.action.ActionMessage;
  8. import org.apache.struts.validator.DynaValidatorForm;
  9. import javax.servlet.ServletContext;
  10. import javax.sql.DataSource;
  11. import javax.servlet.http.*;
  12. public final class RegistAction extends Action{  
  13. public ActionForward execute(
  14. ActionMapping mapping,
  15. ActionForm form,
  16. HttpServletRequest request,  
  17. HttpServletResponse response) throws Exception {
  18.     DynaValidatorForm dyform = (DynaValidatorForm) form;         
  19. String name = (String)dyform.get("name");
  20. String psw1 = (String)dyform.get("psw1");
  21. String psw2 = (String)dyform.get("psw2");
  22.     ServletContext context = servlet.getServletContext();
  23. DataSource dataSource = (DataSource)context.getAttribute("oracleDB1");
  24.         DBUser dbuser = new DBUser(dataSource);
  25.         HttpSession session = request.getSession();
  26.         
  27.         if (dbuser.Insert(name,psw1)!=0) {
  28.       return (mapping.findForward("registSuccessed"));//注册成功
  29. }
  30. else{
  31. ActionMessages errors = new ActionMessages();
  32. errors.add(ActionMessages.GLOBAL_MESSAGE,
  33. new ActionMessage("label.registError"));
  34. if (!errors.isEmpty()) {
  35. saveErrors(request, errors);
  36.    return  mapping.findForward("failed");  //注册失败
  37. }
  38. }
  39. }