This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I'm writing a simple shopping cart application. I need to validate the users and passwords with records in a database. How do I go about designing this application. Please help !! Am I correct if I do the following ?? Login HTML page with a form with name and password fields. Action specifies the .JSP file which will direct user to error page or to the shopping pages depending on the validity of the user. 1. How do I direct user to diferent pages?? 2. Where do I write the database access code ?( in the Bean or the .jsp file ) 3. Where do I write the session handling code ?( Bean or .JSP file) 4. Is a new Bean created for each user ( or for each request, session ) ? Please help. Thanks in advance, Nikhil.
hi, u can redirect the page by using the sendRedirect method in servlets.... u can keep ur validation code in any place .... either bean or in jsp itself.. u write the session handling code in the jsp. thanks vijay
In my opinion even if it is simple application, design as a MVC model. Model-View-Control Design pattern. In this way each one does only its work and nothing else. In servlets web appln make Servlets as controller and businesslogic beans as Model and jsp/other_template_system as View. What it mearly means is 1. use html/jsp forms to collect the user's data. (may be 'Login.html') 2. call the Controller (here a Servlet, maybe 'LoginServlet') 3. The controller verifies if the needed entries are there in the request 4. Calls a Model bean's method by giving the 'loginId' and 'password' (and may be with the databaseConnection also as an sgument) which in turn uses this databaseConn and makes SQL statements to be executed and returns true/false boolean. 6. The servlets just sees the RETUNED boolean and accordingly ROUTES to either cart page or error/Login page again. If you want to give some dynamic data also put the object in session/request by setAttribute("***","***"); methods and then route to the other resource. The idea here is the work is clearly defined between Servlet/BusinessLogicBeans/jsp portions of a web applicaion. If you practice this way, it will really be helpful to expand this idea to complex applns. There are other issues about whether we should use jsp at all, whether we should use session beans at all like that. They are in terms of dividing the work responsblity amoung diff groups and work INDEPENDNTLY and load balancing etc.
I am currently considering several ways of organizing a web site and I am very interested in investigating this design in detail. Can you give us references where this is explained. Books? Examples? Magazine articles? Web sites? Thank you
dear maha, your reply has opened up a fundamental doubt for me... the way ido it is:- have the jsp page use a bean that defines the entire business logic. the jsp page uses the bean to perform its task. what is the role of a servlet in this. why should i use one? divyajot
If you don't mind, I'll pitch my two cents in... If you have only one view and a few beans, then maybe a straight JSP/bean implementation is fine. But what happens if you want a different view based on what is returned by the app or by what the user entered? Now you need some routing or traffic logic. Should this go in the JSP? No, because JSPs should really just be views. In the bean? Well, if the bean is acting as the model (or the interface to the model) then no. The bean shouldn't know about what view needs to go with the data it is providing. A common approach is to use a servlet as the traffic cop. In fact, it is very common that the first thing you hit is the servlet and it determines which JSP needs to be called for the initial display. So that's why a servlet might be involved as part of an MVC approach. John
The only reason for time is so that everything doesn't happen all at once.
- Buckaroo Banzai