日期:2014-05-17 浏览次数:20712 次
<%@ page pageEncoding="UTF-8" %> <%@ page import="bin.*" %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <% if(session.getAttribute("loginUser")!=null) { %> <jsp:forward page="loginSuccess.jsp"/> <% } %> <jsp:useBean id="loginForm" class="bin.LoginFormBean" scope="page"/> <jsp:setProperty name="loginForm" property="*" /> <% if(request.getParameter("s")!=null) { if (loginForm.validate()) { DbUtil db=DbUtil.getInstance(); UserBean user=db.getUser(loginForm.getName()); if(user==null) { loginForm.setErrorMsg("name","no this user!"); } else { if(user.validatePassword(loginForm.getPassword())) { session.setAttribute("loginUser",user); %> <jsp:forward page="loginSuccess.jsp"/> <% } else { loginForm.setErrorMsg("password","password error!"); } } } } %> <form action="login.jsp" method="post" > <p>姓名 <input type="text" name="name" value="<%=loginForm.getName() %>"> <font color=red><%=loginForm.getErrorMsg("name")%></font> </p> <p>密码 <input type="password" name="password" value=<%=loginForm.getPassword() %>> <font color=red><%=loginForm.getErrorMsg("password") %></font> </p> <p> <input type="submit" name="s" value="登录"> </p> </form> </body> </html>