📄 userloginaction.java
字号:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.lideedu.huang.addressBook.struts.action;
import java.lang.reflect.InvocationTargetException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.actions.DispatchAction;
import com.lideedu.huang.addressBook.business.IUserService;
import com.lideedu.huang.addressBook.pojos.User;
import com.lideedu.huang.addressBook.struts.form.UserEnterForm;
import com.lideedu.huang.addressBook.struts.form.UserForm;
public class UserLoginAction extends DispatchAction {
//fileds
IUserService userService;
User user;
// 用户注册
public ActionForward login(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IllegalAccessException, InvocationTargetException {
ActionMessages messages = new ActionMessages();
UserForm userForm = (UserForm) form;
UserEnterForm userEnterForm =new UserEnterForm();
String username = userForm.getUsername();
// 检测用户名是否已被注册
boolean isExisted = userService.checkUser(username);
if (isExisted) {
messages.add("usernameIsExisted", new ActionMessage("usernameIsExisted"));
saveErrors(request, messages);
return new ActionForward(mapping.getInput());
} else {
BeanUtils.copyProperties(user, userForm);
userService.regUser(user);
messages.add("loginSuccess", new ActionMessage("loginSuccess"));
saveErrors(request, messages);
BeanUtils.copyProperties(userEnterForm, userForm);
request.setAttribute("userEnterForm", userEnterForm);
return mapping.findForward("toUserEnterJsp");
}
}
// getter and setter
public IUserService getUserService() {
return userService;
}
public void setUserService(IUserService userService) {
this.userService = userService;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -