forked from maxliaops/Java_Web_Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegAction.java
More file actions
59 lines (58 loc) · 2.04 KB
/
RegAction.java
File metadata and controls
59 lines (58 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.jwy.action;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.jwy.dao.ISpecialtyDao;
import com.jwy.dao.IUserLoginDao;
import com.jwy.dto.Specialty;
import com.jwy.dto.UserLogin;
public class RegAction extends Action {
private IUserLoginDao userLoginDao;
private ISpecialtyDao specialtyDao;
/**
* @param specialtyDao the specialtyDao to set
*/
public void setSpecialtyDao(ISpecialtyDao specialtyDao) {
this.specialtyDao = specialtyDao;
}
/**
* @param userLoginDao the userLoginDao to set
*/
public void setUserLoginDao(IUserLoginDao userLoginDao) {
this.userLoginDao = userLoginDao;
}
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
UserLogin userLogin = new UserLogin();
userLogin.setType("2"); //设置用户类型为学生
userLogin.setLoginName(request.getParameter("loginName"));
userLogin.setPwd(request.getParameter("pwd"));
userLogin.setMail(request.getParameter("mail"));
if(!userLoginDao.findByLoginName(userLogin.getLoginName())){
System.out.println("用户名不存在可以注册");
Integer id = userLoginDao.insert(userLogin); //返回自动生成的主键
request.getSession().setAttribute("id",id);
request.getSession().setAttribute("loginName", userLogin.getLoginName());
//进入到填写基本信息页面
List<Specialty> list = specialtyDao.findStuByAll();
request.setAttribute("list", list);
return mapping.findForward("addStuInfo");
}else{
request.setAttribute("error", "用户名已经存在,不可以注册");
//返回到注册页面
return mapping.findForward("reg");
}
}
}