日期:2014-05-19 浏览次数:20659 次
原文出处: http://www.blogjava.net/lujie2012/archive/2011/11/25/j2ee.html
?
?现在许许多多的初学者和程序员,都在趋之若鹜地学习Web开发的宝典级框架:Struts2,Spring,Hibernate。似乎这些框架成为了一个人是否精通Java,是否会写J2EE程序的唯一事实标准和找工作的必备基础。
- public?class?LoginServlet?extends?HttpServlet?{????
- ????
- ????/*?(non-Javadoc)???
- ?????*?@see?javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest,?javax.servlet.http.HttpServletResponse)???
- ?????*/????
- ????@Override????
- ????protected?void?doPost(HttpServletRequest?req,?HttpServletResponse?resp)?throws?ServletException,?IOException?{????
- ????????String?message?=?null;????
- ????????RequestDispatcher?dispatcher?=?req.getRequestDispatcher("/result.jsp");????
- ????????String?name?=?req.getParameter("name");????
- ????????String?password?=?req.getParameter("password");????
- ????????????
- ????????UserHandler?userHandler?=?new?UserHandler();????
- ????????if(userHandler.authenticate(name,?password))?{????
- ????????????message?=?"恭喜你,登录成功";????
- ????????}?else?{????
- ????????????message?=?"对不起,登录失败";????
- ????????}????
- ????????????
- ????????req.setAttribute("message",?message);????
- ????????dispatcher.forward(req,?resp);????
- ????}????
- }????
- <servlet>????
- ??<servlet-name>Login</servlet-name>????
- ????<servlet-class>????
- ??????com.demo2do.servlet.LoginServlet????
- ??</servlet-class>????
- </servlet>????
- <servlet-mapping>????
- ??<servlet-name>Login</servlet-name>????
- ??<url-pattern>????
- ????/Login????
- ??</url-pattern>????
- </servlet-mapping>????
- <%????
- ?????String?name?=?request.getParameter("name");????
- ?????String?password?=?request.getParameter("password");????
- ????
- ?????UserHandler?userHandler?=?new?UserHandler();????
- ?????if(userHandler.authenticate(name,?password))?{????
- %>????
- <p>恭喜你,登录成功</