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
Joined: Aug 21, 2000
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
Joined: Mar 06, 2001
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.
Joined: Oct 21, 2000
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.