username总是空
//用户
package po; public class Users { private String username; private String password; public Users() { } public String getUsername() { return username; } public void setUesername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }
方法
package dao; import po.Users; public class UserDAO { public boolean usersLogIn(Users u ){ if ("admin".equals(u.getUsername()) &&"admin".equals(u.getPassword())) { return true; } else { return false; } } }
登录
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>用户登录</title> </head> <body> <h1>用户登录</h1> <hr> <form action="dolog.jsp" name="loginForm" method="post"> <table> <tr> <td>用户名</td> <td><input type="text" name="username"/></td> </tr> <tr> <td>密码:</td> <td ><input type="password" name="password"/></td> </tr> <tr> <td colspan="2"><input type="submit" value="登录"></td> </tr> </table> </form> </body> </html>
处理
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <jsp:useBean id="loginUser" class="po.Users" scope="page"></jsp:useBean> <jsp:useBean id="userDAO" class="dao.UserDAO" scope="page"></jsp:useBean> <jsp:setProperty name="loginUser" property="*"></jsp:setProperty> <%request.setCharacterEncoding("utf-8");%> <% String path=request.getContextPath(); String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort();
if (userDAO.usersLogIn(loginUser)){ session.setAttribute("loginUser",loginUser.getUsername()); request.getRequestDispatcher("loginSuccess.jsp").forward(request,response); } else { response.sendRedirect("log_failure.jsp"); }%>