Search code examples
javajsptomcatjavabeans

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


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 properties 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???


Solution

  • 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: