File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Performance: MVC versus Single JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Performance: MVC versus Single JSP" Watch "Performance: MVC versus Single JSP" New topic

Performance: MVC versus Single JSP

Bruno Collins

Joined: Nov 30, 2001
Posts: 19
If I code, lets say, retrieval from a database a list of records that match some criteria. I can do this basically one of two ways, a) Servlet that runs a query, populates a bean and then displays in a JSP -OR- b) do the lot in the JSP.
Which is faster? Does one consume significantly more resources than the other?
Let's ignore for the purpose of this post usual MVC benefits (maintenance & separation of duties etc).
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17410

Typically you should see any performance differences from how the logic is broken out are minimal compared to the overhead of the network and database connections.
When the overhead for keeping things well-structured actually causes significant performance degradation in the server, it's probably time to consider a faster language than Java!
Finally, there's the cardinal rule for optimization: It's virtually ALWAYS easier to optimize a well-structured program than it is to debug an "optimized" one. Along with its corrollary: The bottleneck is almost NEVER where you "know" it is.

An IDE is no substitute for an Intelligent Developer.
Zac Roberts
Ranch Hand

Joined: Jan 29, 2002
Posts: 82
I am fairly new to server side java... are you saying that sometimes it is OK and won't hurt performance if you lump everything into the JSP, assuming maybe it is a very small app with not much worry about code maintanence?

Zac Roberts<br />SCJP2
I agree. Here's the link:
subject: Performance: MVC versus Single JSP
jQuery in Action, 3rd edition