?? registeraction.java
字號(hào):
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(); //驗(yàn)證碼
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");
}
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -