?? regaction.java
字號:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.ascent.struts.action;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
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.ascent.bean.Customer;
import com.ascent.struts.form.RegForm;
/**
* MyEclipse Struts Creation date: 07-07-2007
*
* XDoclet definition:
*
* @struts.action path="/reg" name="regForm" input="reg.jsp" scope="request"
* validate="true"
*/
public class RegAction extends BaseAction {
/*
* Generated Methods
*/
/**
* Method execute
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
RegForm regForm = (RegForm) form;
ActionMessages errors = new ActionMessages();
/**
* 獲得用戶輸入的注冊信息,用戶名、密碼、email
*/
String cust_name = regForm.getCust_name();
String password = regForm.getPassword();
String email = regForm.getEmail();
/**
* 判斷email格式是否正確
*/
Pattern p = Pattern
.compile("^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*[0-9a-zA-Z]+))@([a-zA-Z0-9-]+[.])+([a-zA-Z]{2}|net|com|gov|mil|org|edu|int)$");
Matcher m = p.matcher(email);
if (!m.find()) {
errors.add("email", new ActionMessage("error.email.format"));
saveErrors(request, errors);
return new ActionForward(mapping.getInput());
}
/**
* 判斷用戶名是否存在,如存在則提示用戶名已經存在!
*/
List checkcust = this.getCustomerService()
.findCustomerByName(cust_name);
if (!checkcust.isEmpty()) {
errors.add("custName", new ActionMessage("error.custName.exist"));
saveErrors(request, errors);
return new ActionForward(mapping.getInput());
} else {
/**
* 用戶名不存在則進行注冊,保存到數據庫中
*/
Customer customer = new Customer();
customer.setCust_name(cust_name);
customer.setPassword(password);
customer.setEmail(email);
customer.setFlag(0);
this.getCustomerService().saveCustomer(customer);
return mapping.findForward("regsuccess");
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -