Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

BEANS OR CUSTOM CLASS

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I use beans to put reusable functionality and then use them in my JSP pages. I have also seen code where the functionality is put in a regular class and the class file is imported and the methods are directly used instead of the setProperty etc used with beans?. Which way is better in terms of memory usage/processing? Thanks for any answers
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Correct me if I'm wrong, but I don't think that there is a big difference between using beans and the corresponding JSP tags as opposed to using Java classes in JSP scriptlets. You can always try both versions and compare the resulting Servlets which the JSP engine generates to see exactly how the code differs.
It is probably more of a style question. I would say that if a bean approach works nicely for your problem, go ahead and use it, since it will make the JSP code look a little nicer - in general I think it is always good to put as little Java code on a JSP page as absolutely necessary. But if your problem does not map nicely to a bean with properties, you should probably use a regular Java class with appropriate methods instead.
-Mirko
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would use JavaBeans as much as possible since they can then be used by other Java applications (including other JSPs). If you have situations where the three standard JSP tags for JavaBeans don't work, you can put that functionality into custom tags that have a tag-specific tag handler (Java class), but can still have that tag handler use generic JavaBeans.
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just my $.02 worth. If it fits the model(has properties) make it a bean. I have to mention my FileIO class that I use with my servlets though. It has no properties, it has methods. So I just instantiate it in my servlet and use the methods. Something like that wouldnt map to a bean I dont think.
 
I once met a man from Nantucket. He had a tiny ad
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic