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!
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!
Can you please give some code so that we can advise you.
Mehdi Chaouachi<p>Sun Certified Java Programer (1.4)<br />Sun Certified Web Component Developer (1.4).<br />Sun Certified Mobile Application Developer.
Joined: Jul 22, 2003
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?
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