日期:2014-05-16  浏览次数:20387 次

jsp学习笔记(19)
package servlet.user;
	import java.io.IOException;
	import javax.servlet.RequestDispatcher;
	import javax.servlet.ServletException;
	import javax.servlet.http.HttpServlet;
	import javax.servlet.http.HttpServletRequest;
	import javax.servlet.http.HttpServletResponse;
	import bean.UserBean;
	import util.Validate;
	public class RegServlet extends HttpServlet {
		public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			Validate vd = new Validate();
			UserBean ub = new UserBean();
			String name = vd.getUnicode(request.getParameter("name"));
			String pwd = vd.getUnicode(request.getParameter("pwd"));
			String zname = vd.getUnicode(request.getParameter("zname"));
			String sex = vd.getUnicode(request.getParameter("sex"));
			String age = vd.getUnicode(request.getParameter("age"));
			String noid = vd.getUnicode(request.getParameter("noid"));
			String address = vd.getUnicode(request.getParameter("address"));
			String phone = vd.getUnicode(request.getParameter("phone"));
			String email = vd.getUnicode(request.getParameter("email"));
			String code = vd.getUnicode(request.getParameter("code"));
			String sql = "insert into users(name,pwd,realname,sex,age,card,address,phone,
			email,code) values('"+ name+ "','"+ pwd+ "','"+ zname+ "','"+ sex+ "',
			'"+ age+ "','"+ noid+ "','"+ address+ "','"+ phone+ "','"+ email + "','" + code + "')";
			boolean flag = ub.addUser(sql);
			if (flag == false) {
				request.setAttribute("error", "1");
			} else {
				request.setAttribute("ok", "1");
			}
			RequestDispatcher rd = request.getRequestDispatcher("/user/register.jsp");
			rd.forward(request, response);
		}
		public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			doGet(request, response);
		}
	}