RegisterAction.java
上传用户:sz_mindeo
上传日期:2015-07-22
资源大小:913k
文件大小:1k
源码类别:

Ajax

开发平台:

Java

  1. package com.haiku.struts;
  2. import java.util.List;
  3. import javax.servlet.http.HttpServletRequest;
  4. import javax.servlet.http.HttpServletResponse;
  5. import org.apache.struts.action.Action;
  6. import org.apache.struts.action.ActionForm;
  7. import org.apache.struts.action.ActionForward;
  8. import org.apache.struts.action.ActionMapping;
  9. import org.springframework.context.support.ClassPathXmlApplicationContext;
  10. import com.haiku.bean.Testuser;
  11. import com.haiku.bean.TestuserDAO;
  12. import com.haiku.form.RegisterForm;
  13. public class RegisterAction extends Action
  14. {
  15. public ActionForward execute(
  16. ActionMapping mapping,
  17. ActionForm form,
  18. HttpServletRequest request,
  19. HttpServletResponse response
  20. )
  21. throws Exception
  22. {
  23. RegisterForm myform = (RegisterForm)form;
  24. Testuser transientInstance = new Testuser(myform.getUserName(),myform.getPassword());
  25. ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
  26. TestuserDAO dao =(TestuserDAO)context.getBean("user"); 
  27. String flag = dao.save(transientInstance);
  28. if(flag.equals("注册成功"))
  29. {
  30. request.setAttribute("userName", myform.getUserName());
  31. List list = dao.findAll();
  32. request.setAttribute("userList", list);
  33. return mapping.findForward("success");
  34. }
  35. else
  36. {
  37. return mapping.findForward("failure");
  38. }
  39. }
  40. }