File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes BEANS OR CUSTOM CLASS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "BEANS OR CUSTOM CLASS" Watch "BEANS OR CUSTOM CLASS" New topic
Author

BEANS OR CUSTOM CLASS

PANDU YELAMANCHILI
Greenhorn

Joined: Feb 02, 2001
Posts: 3
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
Mirko Froehlich
Ranch Hand

Joined: Aug 21, 2000
Posts: 114
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
Dustin Marx
Ranch Hand

Joined: Mar 06, 2001
Posts: 40
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.
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

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.


SCJP
Visit my download page
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: BEANS OR CUSTOM CLASS