Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

jsp - JasperException: The value for the useBean class attribute is invalid

org.apache.jasper.JasperException: /index.jsp(1,1) The value for the useBean class attribute com.b5 is invalid.
    org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
    org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
    org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
    org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1272)
    org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1178)
    org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
    org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2411)
    org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2417)
    org.apache.jasper.compiler.Node$Root.accept(Node.java:495)
    org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
    org.apache.jasper.compiler.Generator.generate(Generator.java:3426)
    org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:216)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:332)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:312)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:299)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

Can anyone explain the cause and solution of this problem?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...