• 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

Using Beans in my classes... is it possible?

 
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
I am learning JSP and at first beans sounded like a really cool idea in my JSPs... but when I actually had to write class files, I faced the problem that I can't use beans in there... Weell I guess there's a way.. just that I dont know it
How do u guys go about it?
+ What's EJB? Entity Java Beans? Enterprise Java Beans? Simply Beans? What do the first two mean? And can somebody tell me whats the difference between java EE and java SE? is the enterpirse one commercial or something?
Thank you!
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ivan,
I'm fairly new to this stuff myself, but I can help you out with a few definitions. A bean is actually a class itself which must follow a few rules such as it must provide a no-parameter constructor and its properties must have getter and setter methods. So yes, you will be able to use beans in your classes in the same way you would any other class.
An EJB is an Enterprise Java Bean. This is a bean that can be used in a distributed, or enterprise system. There are session EJBs which usually do something and entity EJBs that are used to hold data, and communicate with a database, for example.
J2SE is the standard Java edition which contains all the stuff you would expect for developing a straightforward application. J2EE is the enterprise edition that contains all the support of an enterprise (distributed) system, including EJBs, CORBA and masses more.
I hope this has helped a bit!
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you please give some code so that we can advise you.
 
Ivan Jouikov
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That still doesnt answer my question: how would you use beans in your classes?
Whenever you use bean in servlet or JSP, its stored in app, session or page map, so it has somewhat global capabilities. But in your classes you do not have access to tomcat's app\session\page maps, thus you can't use those beans....
so how do u go about that?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, remember that a 'bean' is just a Java class that follows certain conventions. Thus, you can 'use' beans wherever you can use Java classes.
You question may be: how do I access beans placed in the various web app contexts from my classes? perhaps...
If so, then you need to pass the context around. Let's say for example you have a bean in the session context. Since the bean is stored in the HTTP session you need to pass the session context to your class (or another means of obtaining it -- the servlet request instance, for example).
You can then use the getAttribute() method to get a reference to the bean and call its method just as any other class.
If that's not what your question is, then I don't understand what you are asking.
hth,
bear
 
Ivan Jouikov
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah, but is there a more... convinient way to do it?
 
girl power ... turns out to be about a hundred watts. But they seriuosly don't like being connected to the grid. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic