createuseraction.java
来自「这是《Struts网络编程实例》一书zhogn 的源代码部分」· Java 代码 · 共 72 行
JAVA
72 行
package org.ithinking.strutsExample.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.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.ithinking.strutsExample.ActionForm.UserInfoActionForm;
import org.ithinking.strutsExample.entity.Userinfo;
import org.ithinking.strutsExample.service.ServiceFactory;
import org.ithinking.strutsExample.service.UserInfoService;
import org.ithinking.strutsExample.serviceImpl.UserInfoUtil;
import org.ithinking.strutsExample.util.SiteContance;
public class CreateUserAction extends Action {
public ActionForward execute(ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {
UserInfoActionForm form = (UserInfoActionForm) actionForm;
UserInfoService userInfoservice = ServiceFactory.getUserinfService();
if (userInfoservice.getUserInfoByLoginId(form.getUserloginid()) != null) {
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
"global.errors.dupicateuser"));
saveErrors(httpServletRequest, errors);
httpServletRequest.setAttribute("UserInfoActionForm", form);
return actionMapping.findForward("newuser");
}
if (!form.getPassword().trim().equals(form.getRepassword().trim())) {
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
"global.errors.passwordwrong1"));
saveErrors(httpServletRequest, errors);
httpServletRequest.setAttribute("UserInfoActionForm", form);
return actionMapping.findForward("newuser");
}
Userinfo userInfo = UserInfoUtil.getUserInfoFromActionForm(form);
try {
if (userInfoservice.saveUser(userInfo)) {
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
"global.saveusersucess"));
saveErrors(httpServletRequest, errors);
httpServletRequest.setAttribute("UserInfoActionForm",
new UserInfoActionForm());
return actionMapping.findForward("newuser");
} else {
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
"global.errors.saveusererror"));
saveErrors(httpServletRequest, errors);
httpServletRequest.setAttribute("UserInfoActionForm", form);
return actionMapping.findForward("newuser");
}
} catch (Exception ex) {
ex.printStackTrace();
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
"global.errors.general"));
saveErrors(httpServletRequest, errors);
return actionMapping.findForward("error");
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?