Forums Register Login

Are javabeans of any use?

+Pie Number of slices to send: Send
Hi
I am new to jsp and javabeans so i'm trying to decide where its best to use beans. AFAIK beans are held in server ram and thus therefore should not be too resource intensive. Bearing this in mind i see no use for them other than maintaining state which can be maintained else where using implicit objects. So my question is, is it a best practice to use beans and if so for what?
Thanks
+Pie Number of slices to send: Send
With respect to JSP, JavaBeans are useful for maintaining state and for representing the information (the model) of your web application. You can use them to wrap up reusable functionality, although custom tags (also known as JSP tag extensions) are the preferred solution.
For a more detailed look at what JavaBeans and custom tags are useful for, check out Chapter 8 (Tag Patterns) of Professional JSP Tag Libraries that is available to download for free.
Hope that's useful
Simon
[ September 26, 2002: Message edited by: Simon Brown ]
+Pie Number of slices to send: Send
this is what i dont understand. I would have thought for reusable functionality the fact that beans stay in memory would mean lots of additional use of server ram for a site that was built in this way. Is this acceptable (i.e. does not harm performance that much)?
thanks
+Pie Number of slices to send: Send
Common practice is to have a Servlet place the bean in an object available to the JSP Page (Request, Session, Context). Usually the Request is used. Once the page is rendered, the Request goes out of scope. Once it goes out of score, all beans placed in it go out of scope. The beans will not stay in memory for long.
The alternative is to create a bean pool type object that recycles the beans.
+Pie Number of slices to send: Send
The main reason for using JavaBeans or any other helper class is to get the Java code out of JSP. The theory being that this helps separate content generation from presentation and makes the whole package more maintainable.
After you have spent countless hours trying to debug a huge JSP that mixes code and HTML you may come to appreciate JavaBeans.
Personally I like the idea of writing a separate test application to thoroughly wring out a JavaBean before using it in JSP.
Bill
+Pie Number of slices to send: Send
Hi
Thanks for the replies. I think its starting to click. Am i right in saying tags exist mainly to access these beans (so that you dont have scriplets and html intermingled). And if so what advantages does using beans have over regular classes ? I think because so many things can be done so many ways the hardest thing to grasp is what to use where and why (i.e what tradeoffs have to be made etc.) in anysight into this or pointers to resources would be gratefully helpful!
Thanks
Kola
+Pie Number of slices to send: Send
Sorry one other thing i wanted to ask, why do servlets place the bean in the request scope why not just do it in the page, is this again to avoid having html and java intermingled?
thanks
I'm not dead! I feel happy! I'd like to go for a walk! I'll even read a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 846 times.
Similar Threads
Where to store Java Bean in Weblogic 5.1?
Construction of JavaBeans in Presentation Tier
using Hibernate in a web application
Java Beans where in weblogic?
just got an interview
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 19:50:32.