JSP:useBean class 属性 "javaPackage.java class" 无效

JSP:useBean class attribute "javaPackage.java class" is invalid

我正在尝试完成本教程:http://www.javatpoint.com/registration-form-in-jsp。但是,当我尝试将一些用户添加到我的数据库时,出现此错误:

org.apache.jasper.JasperException: /register/newAccountCreated.jsp (line: 7, column: 0) The value for the useBean class attribute bean.AppUser is invalid.
    org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
    org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:443)
    org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:149)
    org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1242)
    org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1196)
    org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2392)
    org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2444)
    org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2450)
    org.apache.jasper.compiler.Node$Root.accept(Node.java:474)
    org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2392)
    org.apache.jasper.compiler.Generator.generate(Generator.java:3529)
    org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:251)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:374)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:354)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:341)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:657)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

检查此错误时有人指出我可能遗漏了 jsp:setProperty 但事实并非如此。我的 jsp(我的表单指向的地方)看起来像这样:

<html>
<head>
<%@page import="bean.RegisterUser"%>  
<jsp:useBean id="obj" class="bean.AppUser" />  

<jsp:setProperty property="*" name="obj"/> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>


<%  
int status=RegisterUser.register(obj);  
if(status>0)  
out.print("You Were successfully registered");  

%>  
</body>
</html>

我的 我的 appUser class 片段:

package bean;
public class AppUser {

    private String userName;
    private String userPass;
    private boolean userActive;
    private String userSignInDate;

    public AppUser(String pUserName, String pUserPass){
        this.userActive = true;
        this.userName = pUserName;
        this.userPass = pUserPass;
    }

    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }
    public String getUserPass() {
        return userPass;
    }
    public void setUserPass(String userPass) {
        this.userPass = userPass;
    }
    public boolean isUserActive() {
        return userActive;
    }
    public void setUserActive(boolean userActive) {
        this.userActive = userActive;
    }
    public String getUserSignInDate() {
        return userSignInDate;
    }
    public void setUserSignInDate(String userSignInDate) {
        this.userSignInDate = userSignInDate;
    }
}

问题是您没有为 bean.AppUser class 提供 默认 构造函数。任何时候,您提供一个带有显式构造函数的 class,编译器不再为其提供 默认无参数 构造函数如果一个人没有声明任何构造函数。

<jsp:useBean> 这样的 JSP 标准操作之所以这样命名是因为它们只与 JavaBeans 一起工作。 JavaBean 必须有一个 零参数构造函数 ,并且必须允许使用 getter 和 setter 访问其属性方法。