Reg.java
资源名称:Myblog.rar [点击查看]
上传用户:wlfwy2004
上传日期:2016-12-12
资源大小:33978k
文件大小:4k
源码类别:
Jsp/Servlet
开发平台:
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;
- }
- }