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?
You need the
classattribute instead of thetypeattribute.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-INFand forward to it instead.