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

📄 registeraction.java

📁 地址薄
💻 JAVA
字号:
package actions;


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

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.ActionMessages;
import org.apache.struts.action.ActionMessage;

import forms.UserInfoForm;
import javabean.UserManager;
import javabean.UserInfo;
import javabean.MD5_Encoding;

public class RegisterAction extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub
		UserInfoForm userInfoForm=(UserInfoForm) form;  //获取表单信息
		String name=userInfoForm.getName();  //姓名
		String password=userInfoForm.getPassword();  //密码
		String random=userInfoForm.getRandom();  //验证码
		String email=userInfoForm.getEmail();  //email
		int year=userInfoForm.getYear();  //年
		int month=userInfoForm.getMonth();//月
		int day=userInfoForm.getDay();   //日
		
		ActionMessages errors=new ActionMessages();
		boolean flag=true;
		UserManager userManager=new UserManager();
		if(name.equals("")||name.length()>20)  //如果name为空或length>20
		{
			flag=false;
			errors.add("nameError", new ActionMessage("reg.name.error"));
		}
		if(userManager.isExisted(name))
		{
			flag=false;
			errors.add("nameExisted", new ActionMessage("reg.name.existed"));
		}
		if(password.equals("")||password.length()>20)
		{
			flag=false;
			errors.add("passwordError", new ActionMessage("reg.password.error"));
		}
		String realRandom = request.getSession().getAttribute("random").toString();
		if(random.equals("")||random.length()>4||!random.equals(realRandom))
		{
			flag=false;
			errors.add("randomError", new ActionMessage("reg.random.error"));
		}
		if(email.equals("")||email.length()>20)
		{
			flag=false;
			errors.add("emailError", new ActionMessage("reg.email.error"));
		}
		if(!flag)
		{
			this.saveErrors(request, errors);
			errors.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage("reg.false"));
			return mapping.findForward("false");
		}
		else
		{
			UserInfo userInfo=new UserInfo();
			userInfo.setName(name);
			MD5_Encoding md5 = new MD5_Encoding();
			String md5Pass = md5.getMD5ofStr(password);
			userInfo.setPassword(md5Pass);
			userInfo.setEmail(email);
			String birthday=year+"-"+month+"-"+day;
			userInfo.setBirthday(birthday);
			
			int i=userManager.insertUserInfo(userInfo);
			if(i!=1)
			{
				errors.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage("reg.false"));
				return mapping.findForward("false");
			}
			else
			{
				return mapping.findForward("success");
			}
		}
		
		
	}

}

⌨️ 快捷键说明

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