Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8850963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:01:28+00:00 2026-06-14T13:01:28+00:00

Actually, my task is to make java bean classes inside a same package and

  • 0

Actually, my task is to make java bean classes inside a same package and use them into JSP (java server pages).

Below is what i am doing.

Package name: mypack
*1st class name: UserBean.java* (contains all getters and setters methods)
2nd class name: Databean.java (contains the methods to interact with database)
d:\java: jdk1.5 and tomcat, both are in this folder.

UserBean.java: I want to use the setter and getter methods of this class to set and get the values.
DataBean.java: I want to use this class’s methods to interact with MS Access database like fetch, update, delete etc. For these actions, i want to instantiate UserBean class object into DataBean Class to set and get the values of DataBean class.

How i am compiling?

d:\java\mypack> set path=d:\java\jdk1.5\bin

d:\java\mypack>javac UserBean.java

But when i instantiate UserBean class’s object inside the DataBean Class, i get the error that i have already mentioned.

d:\java\mypack>javac DataBean.java
here i get that above error message

to resolve this issue, i modified the compiling line a little bit:

d:\java\mypack>javac -classpath .. DataBean.java
this works and successfully generates the class file

For now, both classes are being compiled successfully. There is another issue now and is described below.

package mypack;
**//UserBean.java**
public class UserBean{
       String username;    //an attribute of UserBean Class
       String password;    //an attribute of UserBean Class

public UserBean(){} //Default Constructor of UserBean Class
public void setUsername(String username){ this.username = username;   }//setter      method
       public String getUsername(){return username; } //getter method
}

package mypack;
**//DataBean.java**
public class DataBean{
       UserBean user = new UserBean();  //Instantiating UserBean class object in
       //DataBean class
       String username;     //an attribute of DataBean Class

       public DataBean(){}  //Default Constructor of UserBean Class
       public String getUsernameTwo(){return user.getUsername(); } //gettter method
}

On jsp page, i instantiated two objects

<%@ page import="java.sql.*, mypack.*"%> //importing packages
<html>
<body>
<%
UserBean u = new UserBean(); *//UserBean class object u has been instantiated*
DataBean d = new DataBean(); //DataBean class object d has been instantiated

u.setUsername("John");  //username has been set as john
out.println(u.getUsername()); //gets the string john, and prints it successfully 
(prints: John)

out.println(d.getUsernameTwo()); //Does'nt print John, but prints null 
                                 //**(it should print john too but it doesnt)**
%> 
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:01:29+00:00Added an answer on June 14, 2026 at 1:01 pm

    The method getUsernameTwo() returns the user name of a UserBean that has been created in the constructor of DataBean. This UserBean instance is not the same UserBean object as the one that you instantiated in your JSP.

    That’s like opening two bottles, putting a message in one of the bottles, and looking inside the other bottle hoping to find the message you put in the first one. It doesn’t work with bottles, and doesn’t work with Java objects either, because Java objects are somewhat like real objects.

    One thing you could do is to make the DataBean use a UserBean passed in its cnstructor:

    public class DataBean{
        private UserBean user;       
    
        public DataBean(UserBean user) {
            this.user = user;
        }
    
        public String getUsernameTwo() {
            return user.getUsername(); 
        }
    }
    

    And in your JSP:

    <%
    UserBean u = new UserBean();
    DataBean d = new DataBean(u);
    
    u.setUsername("John");
    out.println(u.getUsername());
    out.println(d.getUsernameTwo());
    %>
    

    It seems you haven’t grasped basic OO concepts yet. I would advise starting tutorials on basic Java and OO first, before playing with JSPs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to make Async task execute repeatedly after some time interval just like Timer...Actually
Inside of a Script Task in SSIS, I need to make a call to
This task was actually given to us as homework, but the requirement in the
Actually, I have the task of finding the employees based on the salary rank.
Edit: this is NOT the same as ProgressDialog doesn't show just flashes I make
I am trying to make Drag'n'drop work between 2 QListWidgets and actually do something
I'm trying to make a joomla component and I would like to use it
I like to make services execute two task in a regular time, is it
I am working on a concurrent canvas written in Java which will make the
I need to run a function on my node.js server, that completes the same

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.