This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes JSP and the fly likes which is the best technique to connect jsp with database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "which is the best technique to connect jsp with database" Watch "which is the best technique to connect jsp with database" New topic

which is the best technique to connect jsp with database

mudassir shahab
Ranch Hand

Joined: Oct 13, 2003
Posts: 54
i am creating an online shopping cart softwre using jsp.. i want to know which is the best way to check userid and password(that is how can i interact jsp with database (obviously using jdbc))to check user ids and to store new user record...i am new to jsp..
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
Best way is to not do it in the JSP at all
Have the login request (and every other request) sent to a servlet that (through other classes) does the database interaction and prepares the output data for the JSP (and then forwards the request with that data to the JSP for display).
Use the JSP ONLY for displaying data, never for business logic.
Java code should be limited to the absolutely necessary only like a little loop or counter (though you might consider custom tags for those).

Amit KumarS
Ranch Hand

Joined: Oct 10, 2003
Posts: 100
i think Jeroen Wenting is right.. but i would like to go one step further... i.e. i will like to disaply all data and take input from the users using a JSP page.. i.e. it will work as VIEW.. and all JSP in my application would call one servlet (name it Controller).. with one String as key as hidden value based on which the Controller will another servlet for specific purposes which wil have the bussiness logic like connecting to databases and validating user etc etc
and then this will also return a String as key to another servlet (or same servlet, if your aplication is not large).. depending on which the servlet will decide response is to be commited to which JSP... which will in turn display the data..
This is a good example of MVC architecture.. you can design your own more patterns like this or even cosider STRUTS for such an application if you want...

****************************<br />In 24 hrs Earth rotates once on its Axis.
Don't get me started about those stupid light bulbs.
subject: which is the best technique to connect jsp with database
jQuery in Action, 3rd edition