This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Ivan Jouikov
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • 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!
 
Helen Crosbie
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • 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!
 
Mehdi Chaouachi
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
yeah, but is there a more... convinient way to do it?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic