这个该怎么办好呢?
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Test</title> </head> <body> <form action="com/servlet/LoginServlet" 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> <td> <td><input type="submit" value="登录" /></td> </tr> </table> </form> </body> </html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>LoginSuccess</title> </head> <body> <h1>登录成功!</h1> <jsp:useBean id="loginuser" class="com.entity.User" scope="session" /><br> 欢迎您,<jsp:getProperty name="loginuser" property="username">!<br> </body> </html>
@WebServlet(name = "LoginServlet") public class LoginServlet extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); String username = request.getParameter("username"); String password = request.getParameter("password"); User user = new User(); user.setUsername(username); user.setUsername(password); request.getSession().setAttribute("loginuser",user); if(username.equals("admin")&&password.equals("admin")){ response.sendRedirect(request.getContextPath()+"/loginSuccess.jsp"); } } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request,response); } }
为什么我这登录页面总是跳转不到成功页面呢?
但是系统总是报这行代码错误:
<jsp:getProperty name="loginuser" property="username">