📄 registaction.java
字号:
/* ====================================================================
* $Id$
* ====================================================================
* 文件名 RegistAction.java
* 机能名 注册新用户
* 履历 2005-1-30 dlxu 创建新文件
* Copyright 2004 东南大学 All Rights Reserved
* ====================================================================
*/
package cn.edu.seu.album.web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.log4j.Category;
import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessages;
import cn.edu.seu.album.common.PJAction;
import cn.edu.seu.album.common.PJActionForm;
import cn.edu.seu.album.common.PJBizBroker;
import cn.edu.seu.album.common.PJConst;
import cn.edu.seu.album.common.PJException;
import cn.edu.seu.album.common.StringUtil;
import cn.edu.seu.album.model.RegistNewUserCondition;
import cn.edu.seu.album.model.RegistNewUserRslt;
import cn.edu.seu.album.model.RegistSrchCondtion;
import cn.edu.seu.album.model.SessionBean;
import cn.edu.seu.album.pojo.Person;
/**
* <p> [概 要] 注册新用户</p>
* <p> [详 细] 注册新用户</p>
* <p> [备 考] 无。</p>
*
* @author dlxu
* @version 1.0 2005-1-30
* @since 1.0
*/
/**
* <p> [概 要] </p>
* <p> [详 细] </p>
* <p> [备 考] 无。</p>
*
* @author dlxu
* @version 1.0 2005-1-30
* @since 1.0
*/
public final class RegistAction extends PJAction {
/**
* 日志定义。
*/
private static final Category log = Logger.getInstance(RegistAction.class);
/**
* 成功注册新用户。
*/
private static final String SUC_FORWARD = "success";
/**
* <p> [概 要] 注册新用户</p>
* <p> [详 细] 注册新用户</p>
* <p> [备 考] 无。</p>
* @param mapping
* @param aForm
* @param request
* @param response
* @param errs
* @return
* @throws PJException
* @see cn.edu.seu.album.common.PJAction#doAction(org.apache.struts.action.ActionMapping, cn.edu.seu.album.common.PJActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, org.apache.struts.action.ActionMessages)
*/
protected ActionForward doAction(ActionMapping mapping, PJActionForm aForm,
HttpServletRequest request, HttpServletResponse response,
ActionMessages errs) throws PJException {
log.debug("doAction开始");
ActionForward af = mapping.getInputForward();
log.debug(aForm);
String actionType = aForm.getActionType();
RegistForm form = (RegistForm) aForm;
if (ACTION_INIT.equals(actionType)) {
doInit(form);
} else if (ACTION_SEARCH.equals(actionType)) {
doCheckSearch(form, errs, request);
} else if (ACTION_INSERT.equals(actionType)) {
doNewUser(form, errs, request);
if (errs.isEmpty()) {
af = mapping.findForward(SUC_FORWARD);
}
} else {
throw new PJException(PJConst.ACTION_TYPE_ERR);
}
log.debug("doAction结束");
return af;
}
/**
* <p> [概 要] </p>
* <p> [详 细] </p>
* <p> [备 考] 无。</p>
* @param form
* @param errs
* @param request
* @throws PJException
*/
private void doNewUser(RegistForm form, ActionMessages errs,
HttpServletRequest request) throws PJException {
log.debug("doNewUser开始");
// 去首位空格
String userName = StringUtil.safeTrim(form.getUserName());
String password1 = StringUtil.safeTrim(form.getPassword1());
String password2 = StringUtil.safeTrim(form.getPassword2());
String sex = form.getSex();
String description = StringUtil.safeTrim(form.getDescription());
// 把去除首位空格的字段设回Form。
form.setUserName(userName);
form.setPassword1(password1);
form.setPassword2(password2);
form.setDescription(description);
RegistNewUserCondition cond = new RegistNewUserCondition();
cond.setUserName(userName);
cond.setPassword1(password1);
cond.setPassword2(password2);
cond.setSex(sex);
cond.setDescription(description);
RegistNewUserRslt rslt = (RegistNewUserRslt) PJBizBroker.invoke(
"RegistNewUserBiz", cond, errs, request);
if (errs.isEmpty() && null != rslt) {
Person person = rslt.getPerson();
SessionBean sb = new SessionBean();
sb.setPerson(person);
// 设置会话Bean
HttpSession session = request.getSession(true);
session.setAttribute(PJConst.SESSION_BEAN_KEY, sb);
}
log.debug("doNewUser结束");
}
/**
* <p> [概 要] </p>
* <p> [详 细] </p>
* <p> [备 考] 无。</p>
* @param form
* @param errs
* @param request
* @throws PJException
*/
private void doCheckSearch(RegistForm form, ActionMessages errs,
HttpServletRequest request) throws PJException {
log.debug("doCheckSearch开始");
String userName = StringUtil.safeTrim(form.getUserName());
form.setUserName(userName);
RegistSrchCondtion cond = new RegistSrchCondtion();
cond.setUserName(userName);
PJBizBroker.invoke("RegistCheckBiz", cond, errs, request);
log.debug("doCheckSearch结束");
}
/**
* <p> [概 要] </p>
* <p> [详 细] </p>
* <p> [备 考] 无。</p>
* @param form
*/
private void doInit(RegistForm form) {
log.debug("doInit开始");
form.setSex(PJConst.SEX_MALE);
log.debug("doInit结束");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -