gpt4 book ai didi

javax.servlet.ServletException : bean [name] not found within scope

转载 作者:太空狗 更新时间:2023-10-29 22:43:47 25 4
gpt4 key购买 nike

我收到这个错误:

javax.servlet.ServletException: bean not found within scope

在顶部有这个的页面上。

<jsp:useBean id="bean" type="com.example.Bean" scope="request" />

该类存在于类路径中,它今天早上工作,但我不明白 not found within scope 是什么意思。

这是怎么引起的,我该如何解决?

最佳答案

您需要 class 属性而不是 type 属性。

以下内容:

<jsp:useBean id="bean" type="com.example.Bean" scope="request" />

基本上在幕后做了以下事情:

Bean bean = (Bean) pageContext.getAttribute("bean", PageContext.REQUEST_SCOPE);

if (bean == null) {
throw new ServletException("bean not found within scope");
}

// Use bean ...

虽然以下内容:

<jsp:useBean id="bean" class="com.example.Bean" scope="request" />

基本上在幕后做了以下事情:

Bean bean = (Bean) pageContext.getAttribute("bean", PageContext.REQUEST_SCOPE);

if (bean == null) {
bean = new Bean();
pageContext.setAttribute("bean", bean, PageContext.REQUEST_SCOPE);
}

// Use bean ...

如果它以前工作过但“突然”不工作,则意味着负责将 bean 放入作用域中的某物 已停止工作。例如,在 doGet() 中执行以下操作的 servlet:

request.setAttribute("bean", new Bean());
request.getRequestDispatcher("page.jsp").forward(request, response);

也许您已经通过URL 直接调用了JSP 页面,而不是通过URL 调用了Servlet。如果您想禁用对 JSP 页面的直接访问,请将它们放在 /WEB-INF 中并转发给它。

关于javax.servlet.ServletException : bean [name] not found within scope,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/270444/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com