慕容4496356
2019-03-13 13:50
输入用户名密码,点击登陆按钮后报错:
代码如下:
dologin.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" import = "java.util.*"%> <% request.setCharacterEncoding("utf-8"); %> <jsp:useBean id="userVerify" class = "UsersVerify" scope="application" /> <jsp:useBean id = "loginUser" class = "Users" scope = "application"/> <jsp:setProperty name="loginUser" property="*" /> <% if (userVerify.isValid(loginUser)) { // 成功则转发 session.setAttribute("username", loginUser.getUsername()); request.getRequestDispatcher("success.jsp").forward(request, response); } else { // 登陆失败则重定向 response.sendRedirect("failure.jsp"); } %>
Users.java
public class Users { private String username; private String password; public Users(){} public void setUsername(String username) { this.username = username; } public void setPassword(String password) { this.password = password; } public String getUsername() { return username; } public String getPassword() { return password; } }
UsersVerify.java
public class UsersVerify { // private boolean isValid = false; public UsersVerify() {} public boolean isValid(Users u) { if (u.getUsername().equals("admin") && u.getPassword().equals("123456")) { return true; } return false; } }
java bean的类【必须】放在package里!不能直接放在source下!所以这就是为什么老师的User和UserDao都分别放在com.po和com.dao里
我也遇到了这个问题 楼主解决了吗
点击project中的clean,然后重新运行项目OK了
类的包名也要写出来的,你再试试看
<jsp:useBean id=
"userVerify"
class
=
"UsersVerify"
scope=
"application"
/>
<jsp:useBean id =
"loginUser"
class
=
"Users"
scope =
"application"
/>
你这class没写对,你再重看老师的视频。。。是类的全包名,看你的类在哪个路径下
JAVA遇见HTML——JSP篇
248279 学习 · 3071 问题
相似问题