开发者

org.apache.jasper.JasperException: Cannot find any information on property 'sName' in a bean of type 'AddUserBean'

开发者 https://www.devze.com 2023-01-07 12:44 出处:网络
I have a html page with a user registration form. I collect the data and action is : <form name=\"register\" action=\"../JSP/Register.jsp\" method=\"post\">

I have a html page with a user registration form. I collect the data and action is :

<form name="register" action="../JSP/Register.jsp" method="post">

Then on the jsp page i have

<HTML>
<HEAD>
<TITLE>Reg JSP</TITLE>

    <LINK REL="stylesheet" TYPE="text/css" HREF="commonstyle.css">
</HEAD>
<BODY>
<jsp:useBean id ="user" class ="Data.AddUserBean" />
<jsp:setProperty name ="user" property="*" />

<H1>
    Customer Name :    <jsp:getProperty name = "user" property = "sName" /><br>
    Age :<jsp:getProperty name = "user" property = "iAge" /><br>
    Email:<jsp:getProperty name = "user" property = "sEmail" /><br>

</H1>

The bean is in Package Data; This is a java class having get and set methods for these three prope开发者_Python百科rties sName, iAge and sEmail.

When I am trying to execute the code, it gives me error :

HTTP Status 500 -


type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Cannot find any information on property 'sName' in a bean of type 'Data.AddUserBean'

I am using Tomcat 6 and Eclipse IDE.

Any Suggestions???


Get rid of the Hungarian notation, this makes no sense in an OO language like Java and makes stuff unnecessarily complex in Javabeans and EL. Also get rid of capitalized characters in package names, this is disallowed as per Java Naming Conventions.

package data;

public class AddUserBean { 
    private String name;
    private int age;
    private String email;

    public String getName() { return name; }
    public int getAge() { return age; }
    public String getEmail() { return email; }

    public void setName(String name) { this.name = name; }
    public void setAge(int age) { this.age = age; }
    public void setEmail(String email) { this.email = email; }
}

and rewrite the JSP as follows (capitalized HTML elements is also too '90s, are you sure you're reading up-to-date tutorials/books?):

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Reg JSP</title>
        <link rel="stylesheet" type="text/css" href="commonstyle.css">
    </head>
    <body>
        <jsp:useBean id="user" class="data.AddUserBean" />
        <jsp:setProperty name ="user" property="*" />
        <h1>
            Customer Name: ${user.name}<br>
            Age: ${user.age}<br>
            Email: ${user.email}<br>
        </h1>
    </body>
</html>

Here, the Expression Language (EL, those ${} things) provides you easy instant access to javabeans in any scope. The jsp:getProperty is only useful when there is no EL (nor JSTL) support, but then we're talking about the time before a decade ago. Surely the servletcontainer you're currently using supports EL.

See also:

  • Beginning and intermediate JSP/Servlet tutorials


If your AddUserBean class has properties Name, Age and Email, then why are you asking it for sName, iAge and sEmail? This is inconsistent.


try

<jsp:getProperty name = "user" property = "SEmail" />

I would, however, advice to use simply email, rather than sEmail.


org.apache.jasper.JasperException: Cannot find any information on property 'sName' in a bean of type 'AddUserBean'

Is it the page cannot get my java bean file?

No, it looks more like a problem with your JSPs. Bean property names begin with lowercase letters (unless you expend considerable effort to make it otherwise). It is potentially confusing that the initial lowercase letter by convention appears uppercase in getter and setter names; for example, getEmpName() and setEmpName(String) would be the getter and setter for property empName.

If Jasper couldn't find the bean class then it would have said so; if it goes so far as to check the presence of a particular property then it has already introspected the bean class.


Just Name the Variables as suggested in JAVA naming Convention i.e. in Small Letter. eg.: Private String name;

Private String Name; -----------> will throw exception.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号