[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 301
  • Last Modified:

Java beans

I would like to ask how to compile simple java beans.

Do I need to install extra software, add extra info to the classpath?  Attempts to compile it give me error return type required and it points to the constructor of the bean.  

Can someone help?
0
11pm
Asked:
11pm
  • 4
  • 3
1 Solution
 
objectsCommented:
no extra software required, you need to include any imported classes in the classpath.
What exactly is the error, and on what code is causing it?
0
 
11pmAuthor Commented:
This is the code.  Where can I compile beans.  I have a directory called servlet development from which I compile my servlets, but I can't do the same with beans.

Cheers
 

package business;

public class Customer{
      
    private String firstName;
    private String lastName;
    private String address;
    private String city;
    private String postCode;
    private String companyName;
    private String phoneNumber;
    private String faxNumber;
    private String emailAddress;
    private String creditCardType;
    private String creditCardNumber;
    private String creditCardExpirationDate;

    public Customer(){
          
        firstName = "";
        lastName = "";
        address = "";
        city = "";
        postCode = "";
        companyName = "";
        phoneNumber = "";
        faxNumber = "";
        emailAddress = "";
    }

    public User(String first, String last, String address, String city,
                String postCode, String companyName, String phoneNumber,
                String faxNumber, String email){
                      
        firstName = first;
        lastName = last;
        companyName = companyName;
        emailAddress = email;
        this.address = address;
        this.city = city;
        this.postCode = postCode;
        this.phoneNumber = phoneNumber;
        this.faxNumber = faxNumber;
    }

    public void setFirstName(String f){
        firstName = f;
    }
    public String getFirstName()
    { return firstName; }

    public void setLastName(String l){
        lastName = l;
    }
    public String getLastName()
    { return lastName; }
   
    public void setAddress(String a){
        address = a;
    }
    public String getAddress()
    { return address; }
   
    public void setCity(String c){
        city = c;
    }
    public String getCity()
    { return city; }
   
    public void setPostCode(String p){
        postCode = p;
    }
    public String getPostCode()
    { return postCode; }

    public void setCompanyName(String c){
        companyName = c;
    }
    public String getCompanyName()
    { return companyName; }
   
    public void setPhoneNumber(String pn){
        phoneNumber = pn;
    }
    public String getphoneNumber()
    { return phoneNumber; }
   
    public void setFaxNumber(String fn){
        faxNumber = fn;
    }
    public String getFaxNumber()
    { return faxNumber; }
   
      public void setEmailAddress(String e){
        email = e;
    }
    public String getEmailAddress()
    { return email; }

      public void setCreditCardType(String c){
        creditCardType = c;
    }
    public String getCreditCardType()
    { return creditCardType; }

    public void setCreditCardNumber(String n){
        creditCardNumber = n;
    }
    public String getCreditCardNumber()
    { return creditCardNumber; }

    public void setCreditCardExpirationDate(String s){
        creditCardExpirationDate = s;
    }
    public String getCreditCardExpirationDate()
    { return creditCardExpirationDate; }
}
0
 
objectsCommented:
> package business;

as your bean is in the business package it needs to be in a directory called business

>     public User(String first, String last, String address, String city,

that should be:

    public Customer(String first, String last, String address, String city,
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
KarcOriginCommented:
Change
public User -> public void User

Moreover you have forgotten to diclare email variable

0
 
11pmAuthor Commented:
Thank you, it obviously worked : )
0
 
objectsCommented:
> it obviously worked

but was it what you intended :)
0
 
11pmAuthor Commented:
>Moreover you have forgotten to diclare email variable

Where exactly?

objects, I was too tired and didn't release that acctually you diserved to get these points.  Your answer made it work. Sorry.

I have been working on this  application already for couple of days in a row.  I created this bean, which compiles and is fine, but now I don't know how to connect it to my system.

What is a use keeping these info in the bean?  

I understand that I add the bean to the session and can retrieve the info at any point, is that true?
But how do i do it from jsp and from servlet?  Is it the same mechanism?
0
 
11pmAuthor Commented:
And, sorry, I am new here, what does PQA means next to my questions?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now