Can't use <jsp:useBean>: “Bean cannot be resolved to a type”

99封情书 提交于 2019-12-01 21:55:19

You need to put classes in a package in order to be able to use them in another classes. Classes in the default package are invisible to classes which are by itself in a package (like as the JSP would end up).

So, give the Users class a package like so:

package com.example;

public class Users {
    // ...
}

Recompile and put it in /WEB-INF/classes/com/example/Users.class.

Then you can reference it as follows:

<jsp:useBean id="myBean" class="com.example.Users" />

Unrelated to the concrete problem, having a plural as class name of an entity is usually a smell. Does a single instance of that class really represent multiple users? Why would you not have a List<User> for example? Or does it actually represent a single user? It should then be named User instead.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!