www.pudn.com > Jsp-Blog.rar > RegServlet.java, change:2010-05-20,size:1437b


package myblog.servlet; 
 
import java.io.IOException; 
 
import javax.servlet.ServletException; 
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 
 
import myblog.dao.RegDao; 
 
public class RegServlet extends HttpServlet { 
 
	public void doPost(HttpServletRequest request, HttpServletResponse response) { 
		String username = request.getParameter("login_name").trim(); 
		String password = request.getParameter("pwd1"); 
		String question = request.getParameter("password_question"); 
		String answer = request.getParameter("password_answer").trim(); 
		String email = request.getParameter("e_mail").trim(); 
		String sex = request.getParameter("sex"); 
		String content = request.getParameter("introduce"); 
		RegDao reg = new RegDao(); 
		int number =reg.repeat(username); 
		 
		if (number == 3) { 
			request.setAttribute("regmsg", "此用户名已存在,请换一个!"); 
 
		}else{ 
			int num = reg.Reg(username, password, question, answer, email, sex, 
					content); 
			 if(num==1){ 
				request.setAttribute("regmsg", "注册成功!"); 
			}else{ 
				request.setAttribute("regmsg", "注册失败!"); 
			} 
		} 
			 
		try { 
			request.getRequestDispatcher("reg.jsp").forward(request,response); 
		} catch (ServletException e) {			 
			e.printStackTrace(); 
		} catch (IOException e) {		 
			e.printStackTrace(); 
		} 
	} 
 
}