views:

37

answers:

3

Hi,

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

A: 

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

skaffman
Sir the property name is sName, iAge, sEmail
Tara Singh
@Tara: OK, I see the edit. Those are very odd property names. Please post the actual source for the class, rather than just describing it.
skaffman
A: 

try

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

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

Bozho
A: 

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:

BalusC
Hi, I tried everything and also renamed all the properties to lowercase. Still the same error. Id there some special setting or mapping required for Eclipse ?
Tara Singh
If you get the same error, then you haven't changed the code accordingly or not rebuilt/redeployed the code correctly. Cleanup everything and retry.
BalusC