How can i use the class that i wrote in other jsp file?

85 Views Asked by At

I'm a beginner in JSP. I wrote a package for userdata like this:

package user;
    public class UserData {
    String username;
    String email;
    int age;
    public void setUsername( String value )
    {
        username = value;
    }
    public void setEmail( String value )
    {
        email = value;
    }
    public void setAge( int value )
    {
        age = value;
    }
    public String getUsername() { return username; }
    public String getEmail() { return email; }
    public int getAge() { return age; }
}

But when i try to do:

 <jsp:useBean id="user" class="user.UserData" scope="session"/>

In another jsp file, I get an error like this:

Undefined type: user.UserData 

How can I use my new class on the other jsp file?

1

There are 1 best solutions below

0
On

Skeleton of jsp useBean:

 <jsp:useBean id="id" class="bean's class" scope="bean's scope">
  <jsp:setProperty name="bean's id" property="property name"  
                value="value"/>
  <jsp:getProperty name="bean's id" property="property name"/>

 </jsp:useBean>