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

📄 regaction.java

📁 利用Java开发的网上书店系统
💻 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 + -