There is nothing wrong by putting the database connection in the JSP,
Yes there is. You have obviously never worked on anything that lasted more than a few days, or ever needed to be expanded or improved or fixed. Scriptlets are a maintenance
nightmare. At the very least use a bean.
but you have to create a new database connection and query for every page you creates.
Hopefully you mean retreiving one from a Connection pool and
not actually creating one with every query. That would be a
performance nightmare.
This will reduse the performance and response on server. This is one of the problems.
(I guess you didnt mean using a pool.) Not with a Connection Pool, and
every web container (which you must be using to use JSP) has a connection pool, so no problem.
Instead you could create a connection class and put it into application scope and the connection will be made when server is started. This is done only once. Then it is available for all objects that uses table info from the database.
Yet
another bad suggestion. A static, single connection used by a dynamic (God I hate that word) threaded application? What happens when one thread calls rollback directly before another thread was about call commit? Or the other way around?
Connection Pools, Beans, and a
properly implemented layered approach. Everything presented here is ....... well, I don't think I
really need to say it.