⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reg.java

📁 是一个网站的博客系统
💻 JAVA
字号:
package com.opensource.blog.web.action;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.Action;
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 com.laoer.comm.util.Util;
import com.opensource.blog.exception.BlogException;
import com.opensource.blog.model.Blog;
import com.opensource.blog.model.UserInfo;
import com.opensource.blog.service.UserInfoService;
import com.opensource.blog.web.form.RegForm;

public class Reg
    extends Action {

  private UserInfoService userInfoService;

  public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm,
                               HttpServletRequest servletRequest,
                               HttpServletResponse servletResponse) {
    ActionMessages errors = new ActionMessages();
    RegForm form = (RegForm) actionForm;

    if (form.getAction().equalsIgnoreCase("new")) {
      form.setAction("add");
      return actionMapping.findForward("reg");
    }
    if (form.getAction().equalsIgnoreCase("add")) {

      UserInfo ui = this.getUserInfoService().findUserInfoByUserName(form.getUsername());

      if (ui != null) {
        errors.add("error.reg.username2", new ActionMessage("error.reg.username2"));
        saveErrors(servletRequest, errors);
        return actionMapping.getInputForward();
      }

      ui = this.getUserInfoService().findUserInfoByEmail(form.getEmail());
      if (ui != null) {
        errors.add("error.reg.email", new ActionMessage("error.reg.email"));
        saveErrors(servletRequest, errors);
        return actionMapping.getInputForward();
      }

      ui = new UserInfo();
      try {
        BeanUtils.copyProperties(ui, form);
      }
      catch (Exception e) {
      }
      ui.setFace(0);
      ui.setSign("");
      ui.setLastlogintime(Util.getLongTime());
      ui.setLastloginip(servletRequest.getRemoteAddr());
      ui.setLogintimes(0);
      Blog blog = new Blog();
      blog.setArttotal(0);
      blog.setBlogname(form.getBlogname());
      blog.setCalendarstyle(0);
      blog.setCansee(form.getCansee());
      blog.setCounterstyle(0);
      blog.setDescription(form.getDescription());
      blog.setHits(0);
      blog.setLetterbookmark(0);
      blog.setLogosize("80*31");
      blog.setLogourl("");
      blog.setMultiuser(1);
      blog.setNewlyartnum(5);
      blog.setNewlycomnum(5);
      blog.setNotetotal(0);
      blog.setPerartnum(8);
      blog.setPicbookmark(0);
      blog.setPro(form.getPro());
      blog.setRegtime(new Date());
      blog.setSkin(form.getSkin());
      blog.setUsername(form.getUsername());

      try {
        Object[] o = this.getUserInfoService().createUserAndBlog(ui, blog);
        return actionMapping.findForward("regok");
      }
      catch (BlogException ex) {
        errors.add("error.reg.reguser", new ActionMessage("error.reg.reguser"));
        saveErrors(servletRequest, errors);
        return actionMapping.getInputForward();
      }

    }
    return actionMapping.findForward("error");
  }

  public UserInfoService getUserInfoService() {
    return userInfoService;
  }

  public void setUserInfoService(UserInfoService userInfoService) {
    this.userInfoService = userInfoService;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -