📄 registeraction.java
字号:
package org.whatisjava.dang.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
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.MappingDispatchAction;
import org.whatisjava.dang.domain.User;
import org.whatisjava.dang.form.UserForm;
import org.whatisjava.dang.service.AuthorizeService;
import org.whatisjava.dang.util.Constants;
import org.whatisjava.dang.util.CookieUtils;
import org.whatisjava.dang.util.EmailUtils;
public class RegisterAction extends MappingDispatchAction {
private AuthorizeService as = new AuthorizeService();
/**
*
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward showOne(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
return mapping.findForward("success");
}
/**
*
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward showTwo(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
return mapping.findForward("success");
}
/**
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward one(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
UserForm f = (UserForm) form;
User user = new User();
BeanUtils.copyProperties(user, f);
as.addUser(user);
EmailUtils.sendEmail(user.getEmail(), "title", user.getVerifyCode()
+ "-" + user.getId());
return mapping.findForward("success");
}
/**
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward two(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
UserForm f = (UserForm) form;
String code = f.getVerifyCode();
Integer id = null;
try {
id = Integer.parseInt(code.substring(code.lastIndexOf("-") + 1));
} catch (NumberFormatException e) {
}
if (id != null) {
User user = as.verifyEmail(id, code.substring(0, code
.lastIndexOf("-")));
if (user != null) {
CookieUtils.addCookie(response, CookieUtils.USER_ID, String
.valueOf(user.getId()));
HttpSession session = request.getSession();
session.setAttribute(Constants.SID_USER, user);
return mapping.findForward("success");
}
}
ActionMessages msg = new ActionMessages();
msg.add("error.verify.email", new ActionMessage("error.verify.email"));
saveErrors(request, msg);
return mapping.getInputForward();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -