Reg.java
上传用户:wlfwy2004
上传日期:2016-12-12
资源大小:33978k
文件大小:4k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. package com.opensource.blog.web.action;
  2. import java.util.Date;
  3. import javax.servlet.http.HttpServletRequest;
  4. import javax.servlet.http.HttpServletResponse;
  5. import org.apache.commons.beanutils.BeanUtils;
  6. import org.apache.struts.action.Action;
  7. import org.apache.struts.action.ActionForm;
  8. import org.apache.struts.action.ActionForward;
  9. import org.apache.struts.action.ActionMapping;
  10. import org.apache.struts.action.ActionMessage;
  11. import org.apache.struts.action.ActionMessages;
  12. import com.laoer.comm.util.Util;
  13. import com.opensource.blog.exception.BlogException;
  14. import com.opensource.blog.model.Blog;
  15. import com.opensource.blog.model.UserInfo;
  16. import com.opensource.blog.service.UserInfoService;
  17. import com.opensource.blog.web.form.RegForm;
  18. public class Reg
  19.     extends Action {
  20.   private UserInfoService userInfoService;
  21.   public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm,
  22.                                HttpServletRequest servletRequest,
  23.                                HttpServletResponse servletResponse) {
  24.     ActionMessages errors = new ActionMessages();
  25.     RegForm form = (RegForm) actionForm;
  26.     if (form.getAction().equalsIgnoreCase("new")) {
  27.       form.setAction("add");
  28.       return actionMapping.findForward("reg");
  29.     }
  30.     if (form.getAction().equalsIgnoreCase("add")) {
  31.       UserInfo ui = this.getUserInfoService().findUserInfoByUserName(form.getUsername());
  32.       if (ui != null) {
  33.         errors.add("error.reg.username2", new ActionMessage("error.reg.username2"));
  34.         saveErrors(servletRequest, errors);
  35.         return actionMapping.getInputForward();
  36.       }
  37.       ui = this.getUserInfoService().findUserInfoByEmail(form.getEmail());
  38.       if (ui != null) {
  39.         errors.add("error.reg.email", new ActionMessage("error.reg.email"));
  40.         saveErrors(servletRequest, errors);
  41.         return actionMapping.getInputForward();
  42.       }
  43.       ui = new UserInfo();
  44.       try {
  45.         BeanUtils.copyProperties(ui, form);
  46.       }
  47.       catch (Exception e) {
  48.       }
  49.       ui.setFace(0);
  50.       ui.setSign("");
  51.       ui.setLastlogintime(Util.getLongTime());
  52.       ui.setLastloginip(servletRequest.getRemoteAddr());
  53.       ui.setLogintimes(0);
  54.       Blog blog = new Blog();
  55.       blog.setArttotal(0);
  56.       blog.setBlogname(form.getBlogname());
  57.       blog.setCalendarstyle(0);
  58.       blog.setCansee(form.getCansee());
  59.       blog.setCounterstyle(0);
  60.       blog.setDescription(form.getDescription());
  61.       blog.setHits(0);
  62.       blog.setLetterbookmark(0);
  63.       blog.setLogosize("80*31");
  64.       blog.setLogourl("");
  65.       blog.setMultiuser(1);
  66.       blog.setNewlyartnum(5);
  67.       blog.setNewlycomnum(5);
  68.       blog.setNotetotal(0);
  69.       blog.setPerartnum(8);
  70.       blog.setPicbookmark(0);
  71.       blog.setPro(form.getPro());
  72.       blog.setRegtime(new Date());
  73.       blog.setSkin(form.getSkin());
  74.       blog.setUsername(form.getUsername());
  75.       try {
  76.         Object[] o = this.getUserInfoService().createUserAndBlog(ui, blog);
  77.         return actionMapping.findForward("regok");
  78.       }
  79.       catch (BlogException ex) {
  80.         errors.add("error.reg.reguser", new ActionMessage("error.reg.reguser"));
  81.         saveErrors(servletRequest, errors);
  82.         return actionMapping.getInputForward();
  83.       }
  84.     }
  85.     return actionMapping.findForward("error");
  86.   }
  87.   public UserInfoService getUserInfoService() {
  88.     return userInfoService;
  89.   }
  90.   public void setUserInfoService(UserInfoService userInfoService) {
  91.     this.userInfoService = userInfoService;
  92.   }
  93. }