JSP:useBean类属性" javaPackage.java类"是无效的

时间:2015-03-26 02:19:05

标签: java oracle jsp javabeans

我正在尝试做这个教程: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类代码段:

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;
    }
}

1 个答案:

答案 0 :(得分:1)

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

<jsp:useBean>这样的JSP标准操作是这样命名的,因为它们仅适用于JavaBeans。 JavaBean 必须具有零参数构造函数,并且必须允许使用getter和setter方法访问其属性。