UserAction.java
上传用户:wok5188
上传日期:2018-02-20
资源大小:1835k
文件大小:4k
源码类别:

MySQL数据库

开发平台:

Java

  1. /*
  2.  * Generated by MyEclipse Struts
  3.  * Template path: templates/java/JavaClass.vtl
  4.  */
  5. package com.center.control;
  6. import java.io.IOException;
  7. import java.sql.ResultSet;
  8. import java.sql.SQLException;
  9. import java.util.ArrayList;
  10. import java.util.HashMap;
  11. import java.util.Map;
  12. import javax.servlet.http.HttpServletRequest;
  13. import javax.servlet.http.HttpServletResponse;
  14. import javax.servlet.http.HttpSession;
  15. import org.apache.struts.action.ActionForm;
  16. import org.apache.struts.action.ActionForward;
  17. import org.apache.struts.action.ActionMapping;
  18. import org.apache.struts.actions.LookupDispatchAction;
  19. import com.center.commons.DataConnect;
  20. import com.center.dto.UserDTO;
  21. import com.center.model.UserManager;
  22. import com.center.util.DealString;
  23. import com.center.vo.UserVO;
  24. import com.mysql.jdbc.Connection;
  25. /** 
  26.  * MyEclipse Struts
  27.  * Creation date: 05-18-2007
  28.  * 
  29.  * XDoclet definition:
  30.  * @struts.action path="/user" name="userForm" input="/show/admin/user.jsp" parameter="method" scope="request" validate="true"
  31.  * @struts.action-forward name="ok" path="/ok.jsp"
  32.  * @struts.action-forward name="err" path="/err.jsp"
  33.  */
  34. public class UserAction extends LookupDispatchAction {
  35. /*
  36.  * Generated Methods
  37.  */
  38. /** 
  39.  * Method execute
  40.  * @param mapping
  41.  * @param form
  42.  * @param request
  43.  * @param response
  44.  * @return ActionForward
  45.  */
  46. public HttpSession session;
  47. private Connection conn;
  48. private UserDTO userdto;
  49. private UserManager usermanager;
  50. public ActionForward regist(ActionMapping mapping, ActionForm form,
  51. HttpServletRequest request, HttpServletResponse response) throws SQLException, IOException {
  52. UserForm UserForm = (UserForm) form;// TODO Auto-generated method stub
  53. System.out.println("hell");
  54. conn = (Connection) new DataConnect().getConn();
  55. userdto = new UserDTO();
  56. userdto.setUsername(UserForm.getUsername());
  57. userdto.setUserpsw(UserForm.getUserpsw());
  58. userdto.setUseremail(UserForm.getUseremail());
  59. userdto.setUsertime(new DealString().getDateTime());
  60. System.out.println("sss");
  61. if(userdto != null || !userdto.equals("")){
  62. usermanager = new UserManager(conn);
  63. int i = usermanager.regist(userdto);
  64. if(i == 1){
  65. usermanager = new UserManager(conn);
  66. UserVO uservo = usermanager.login(userdto);
  67. if(uservo != null){
  68. System.out.println(uservo.getUsername());
  69. session = request.getSession();
  70. session.setAttribute("username", uservo);
  71. response.sendRedirect(request.getContextPath()+"/show/admin/registok.jsp");
  72. }else{
  73. response.sendRedirect(request.getContextPath()+"/show/admin/registerr.jsp");
  74. }
  75. }else{
  76. response.sendRedirect(request.getContextPath()+"/show/admin/registerr.jsp");
  77. }
  78. }
  79. conn.close();
  80. return null;
  81. }
  82. public ActionForward login(ActionMapping mapping, ActionForm form,
  83. HttpServletRequest request, HttpServletResponse response) throws SQLException, IOException {
  84. UserForm UserForm = (UserForm) form;// TODO Auto-generated method stub
  85. conn = (Connection) new DataConnect().getConn();
  86. userdto = new UserDTO();
  87. userdto.setUsername(UserForm.getUsername());
  88. userdto.setUserpsw(UserForm.getUserpsw());
  89. System.out.println(userdto.getUsername());
  90. if(userdto != null || !userdto.equals("")){
  91. usermanager = new UserManager(conn);
  92. UserVO uservo = usermanager.login(userdto);
  93. if(uservo != null){
  94. session = request.getSession();
  95. session.setAttribute("username", uservo);
  96. response.sendRedirect(request.getContextPath()+"/show/admin/registok.jsp");
  97. }else{
  98. response.sendRedirect(request.getContextPath()+"/show/admin/registerr.jsp");
  99. }
  100. }
  101. conn.close();
  102. return null;
  103. }
  104. protected Map getKeyMethodMap() {
  105. // TODO Auto-generated method stub
  106. HashMap map = new HashMap();
  107. map.put("button.regist", "regist");
  108. map.put("button.login", "login");
  109. return map;
  110. }
  111. }