• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Quick question on calling getter/setters

 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
calling HttpSession bean getter/setter from a JSP or Servlet is easy, but how do I pass a Bean to another class?

I have a servlet for creating a user account, it populates a HttpSession Bean with the user's details, I want to pass this Bean over to another Class which connects to a DB and uses a SQL 'INSERT' to add the details to the DB.

Any help appreciated

KS
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Classes don't connect to things; methods connect to things, and then only when someone calls them -- right? So when you call this connecting method, you want to pass the bean as an argument to the connecting method -- that might entail changing the method's argument list.

That help?
 
Kevin P Smith
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah sorry that's what I meant, so I have a Servlet that does:

UserDetailsBean userDetails = new UserDetailsBean();
userDetails.setXYZ(....

Then I call:

IUserAccountManager usrAccMan= new UserAccountManager();
usrAccMan.createUsrAcc(userDetails);


Then in the UserAccountManager class I can have a method

createUsrAcc(UserDetailsBean userDetails )
userDetials.getXYZ(...
 
Kevin P Smith
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Following on from this, I have always used a Bean in the context of HttpSession Bean 9quick lighweight alternative to EJB Session bean).

But for this system i am using it [Bean] merely as a temporary storage for a user's details on registration.

All the details (name, address, email, user etc etc etc) are set in a Bean by the Servlet then passed to another class which will take those details and run some SQL stuffy to create the account in my DB.

thing is, once this is done, how do i 'destroy' the UserBean? it's not stored in the session just passed from CreateAccountServlet.class to CreateAccountSQL.class.

Or

Is there a better method, recommended of doing this e.g. passing eveything over to the method
CreateAccountServlet.createAccount(String fname, String sname... String password...) etc etc etc. Or in a vector or something?

What would be the recommened method of doing this?
 
His brain is the size of a cherry pit! About the size of this ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic