www.pudn.com > restrant.zip > RegisterServlet.java, change:2014-03-10,size:2224b


package com.alex.restrantol.servlet; 
 
import java.io.IOException; 
import java.util.Enumeration; 
import java.util.Map; 
 
import javax.servlet.ServletException; 
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 
 
import com.alex.restrantol.entity.UserEntity; 
import com.alex.restrantol.service.UserService; 
import com.alex.restrantol.dao.UserDao; 
 
public class RegisterServlet extends HttpServlet { 
 
	public void doPost(HttpServletRequest req, HttpServletResponse res) 
			throws ServletException, IOException { 
		String type = req.getParameter("type"); 
		if ("reg".equals(type)) { 
			String temp = req.getParameterNames().toString(); 
			String username = req.getParameter("loginname"); 
			UserEntity user =null; 
			if(username != null && username.trim().length() > 0) 
					user = new UserDao().findUserIsExist(username); 
			if(user != null){ 
				req.setAttribute("loginname_error", "该用户名已经存在!"); 
				req.getRequestDispatcher("/register.jsp").forward(req, res); 
			}else{ 
				if(temp == null || temp.length() == 0){ 
				req.getRequestDispatcher("/register.jsp").forward(req, res); 
				}else{ 
					Map<String,String[]> map = req.getParameterMap(); 
					UserService userService = new UserService(); 
					userService.addUser(map); 
					req.getRequestDispatcher("login.jsp").forward(req, res); 
				} 
			} 
		}else if("adminReg".equals(type)){ 
			String temp = req.getParameterNames().toString(); 
			String username = req.getParameter("loginname"); 
			UserEntity user =null; 
			if(username != null && username.trim().length() > 0) 
					user = new UserDao().findUserIsExist(username); 
			if(user != null){ 
				req.setAttribute("loginname_error", "该用户名已经存在!"); 
				req.getRequestDispatcher("/register.jsp").forward(req, res); 
			}else{ 
				if(temp == null || temp.length() == 0){ 
				req.getRequestDispatcher("/register.jsp").forward(req, res); 
				}else{ 
					Map<String,String[]> map = req.getParameterMap(); 
					UserService userService = new UserService(); 
					userService.addUser(map); 
					res.sendRedirect("/restrant/login.jsp"); 
				} 
			} 
		} 
	} 
}