The moose likes JSP and the fly likes Why DB connections are not written directly in JSPs ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Why DB connections are not written directly in JSPs ?" Watch "Why DB connections are not written directly in JSPs ?" New topic

Why DB connections are not written directly in JSPs ?

Sim Kim
Ranch Hand

Joined: Aug 06, 2004
Posts: 268
My Reasons :
a)Response is slow
b) Not a standard J2EE architecture
c) Load Balancing is not possible

Which one is correct ?
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Whenever someone enters multiple choice questions into a forum, my first assumption is that they have copied and pasted from a homework assignment.

Which do you think it is?

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
I don't think it's homework, I mean, what with a 95% on the SCJP!

There is no emoticon for what I am feeling!
Paul Bourdeaux
Ranch Hand

Joined: May 24, 2004
Posts: 783
It sounds like homework to me too... but I will give it a shot anyway.

I tend to learn toward the fact that it is not standard J2EE architecture. I am a MVC Model 2 advocate, and I maintain that a JSP should only be used as the view. The place for database logic is in the model. Also, let's remember that we should be using database connection pooling in a J2EE application anyway.

As far as the other two... Is the response slower if you code a database connection directly into the JSP? I doubt it because all JSPs are compiled into a servlet anyway, so they should be executed just as quickly (with the exception of thefirst time of course). I could be wrong though... if someone knows differently, I would be interested in their thoughts.

And what does load balancing have to do with it? I fail to see how distributing processing and communications activity evenly across a computer network will no longer be possible just because you put a database connection into a JSP...
[ November 22, 2005: Message edited by: Paul Bourdeaux ]

“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook
I agree. Here's the link:
subject: Why DB connections are not written directly in JSPs ?
It's not a secret anymore!