出现问题:Unable to compile class for JSP; UsersVerify cannot be resolved to a type
输入用户名密码,点击登陆按钮后报错:
代码如下:
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; } }