javax.servlet.ServletException:在范围内找不到 bean [名称]
我收到此错误:
javax.servlet.ServletException: bean not found within scope
在顶部有此错误的页面上。
<jsp:useBean id="bean" type="com.example.Bean" scope="request" />
该类存在于类路径中,它今天早上工作了,但我不明白在范围内找不到什么意思。
这是如何引起的以及如何解决?
I'm getting this error:
javax.servlet.ServletException: bean not found within scope
on a page with this at the top.
<jsp:useBean id="bean" type="com.example.Bean" scope="request" />
The class exists in the classpath, it worked this morning, and I don't get what not found within scope means.
How is this caused and how can I solve it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要
class
属性而不是type
属性。以下:
在幕后基本上执行以下操作:
而以下:
在幕后基本上执行以下操作:
如果它之前有效并且“突然”不起作用,那么这意味着负责将 bean 放入作用域的某物已停止工作。 例如,一个 Servlet 在
doGet()
中执行以下操作:也许您直接通过 URL 调用 JSP 页面,而不是通过 URL 调用 Servlet。 如果您想禁用对 JSP 页面的直接访问,请将它们放入
/WEB-INF
中并转发到它。You need the
class
attribute instead of thetype
attribute.The following:
does basically the following behind the scenes:
While the following:
does basically the following behind the scenes:
If it has worked before and it didn't work "in a sudden", then it means that something which is responsible for putting the bean in the scope has stopped working. For example a servlet which does the following in the
doGet()
:Maybe you've invoked the JSP page directly by URL instead of invoking the Servlet by URL. If you'd like to disable direct access to JSP pages, then put them in
/WEB-INF
and forward to it instead.您必须添加
因为默认情况下,bean 是在 页面范围
You must add
Because by default the bean is looked on the page scope