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

jsp学习笔记(17)
package servlet.user;
	import java.io.IOException;
	import java.util.ArrayList;
	import javax.servlet.RequestDispatcher;
	import javax.servlet.ServletException;
	import javax.servlet.http.HttpServlet;
	import javax.servlet.http.HttpServletRequest;
	import javax.servlet.http.HttpServletResponse;
	import javax.servlet.http.HttpSession;
	import util.Validate;
	import bean.UserBean;
	public class UserLoginServlet extends HttpServlet {
		public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			Validate vd = new Validate();
			String name = vd.getUnicode(request.getParameter("name"));
			String pwd = vd.getUnicode(request.getParameter("pwd"));
			UserBean ub = new UserBean();
			String sql1="select * from users where name='" + name
			+ "' and pwd= '" + pwd + "'";
			ArrayList<?> alList= ub.getLoginUser(sql1);
			if(alList!=null){
				HttpSession session = request.getSession();
				session.setAttribute("login", alList);
			}
			if (alList==null) {
				request.setAttribute("loginError", "error");
			}
			RequestDispatcher rd = request.getRequestDispatcher("/user/index.jsp");
			rd.forward(request, response);
			}
			public void doPost(HttpServletRequest request, HttpServletResponse response)
				throws ServletException, IOException {
			doGet(request, response);
		}
	}