The value for the useBean class attribute com.b5 is invalid.
So you have a
<jsp:useBean id="b5" class="com.b5" />
This exception is typical when the following happening "behind the scenes" fails:
com.b5 b5 = new com.b5();
Apart from the requirement that it should be placed inside a package (which you thus correctly did), the bean should itself be a public
class and have an (implicit) public
no-arg constructor. I.e.
package com;
public class b5 {
public b5() {
// Default constructor is optional when there are no other constructors.
}
}
Normally this constructor is already present, but this will be hidden whenever you add other constructors which take other arguments. You'll then need to add it yourself explicitly.
package com;
public class b5 {
public b5(String argument) {
// Non-default constructor.
}
public b5() {
// You need to explicitly add a default constructor.
}
}
Another possible cause is that the bean class cannot be found in the runtime classpath. If this is your own bean, then ensure that its class
file is located in /WEB-INF/classes/com/b5.class
. Also ensure that the full qualified name com.b5
is literally correct, it's case sensitive. You should then look a bit further in the stacktrace for the exact cause of the problem. Head to the root cause
or caused by
parts at the bottom of the trace.
That said (and unrelated to the actual problem), the classname b5
is a pretty poor choice. It should be a sensible name starting with uppercase, e.g. User
, Product
, Order
, etc. Also, using <jsp:useBean>
instead of a servlet-based controller is a poor practice. If you're new to servlets, start at out servlets wiki page.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…