简体   繁体   中英

Servlet returning JSTL Result or a List of Objects?

Assuming Tomcat 7, MySql 5.5, and JSPs, and hand coded DAOs...

From the perspactive of a "production" application, is there a significant preference between the following query architectures?

In either case the servlet calls a DAO to get the items then passes them to a JSP for display within an Attribute.

1) The DAO returns a JSTL Result using: result = ResultSupport.toResult(rs);

2) The DAO returns a List containing Objects full of data.

To me it seems that Objects are better if you are going to materially operate on them. ie update them. But a List of Objects is too much work for just displaying a table of data. For a heavily used application it seems the lists will consume a lot of server resources with little real benefit. Plus, it seems that joining tables for different display requirements would require a ton of coding work and maintenance.

It seem that having a DAO return a JSTL Result for light weight display purposes would be much easier on the server and wold also be much easier to code an maintain.

I know that using the JSTL SQL tags in the JSP is frowned upon in a production environment - though I never really understood why... Would using a JSTL Result in a Java servlet attract the same negative opinion?

I have not been able to find a definitive guide explaining the preferred architecture between these two approaches. Given the convenience of the JSTL Result, I'm surprised it is mentioned so infrequently?

Any thoughts?

Thanks

The main idea of DAO is to encapsulate data access logic and isolate it from business logic. Option 2 does just that.

Option 1 makes business logic tightly coupled with data model, since it will need to know the exact structure of the recordset. If you decide to refactor your database implementation you will have to re-write a part of your business logic layer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM