File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Designing applications using JSP, Beans and Servlets and HTML ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Designing applications using JSP, Beans and Servlets and HTML ??" Watch "Designing applications using JSP, Beans and Servlets and HTML ??" New topic

Designing applications using JSP, Beans and Servlets and HTML ??

Trader Joey
Ranch Hand

Joined: May 11, 2000
Posts: 33
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,
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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.
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
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.

maha anna
Humberto Hernandez

Joined: Nov 01, 2000
Posts: 13
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.
Magazine articles?
Web sites?
Thank you
Divyajot Ahluwalia
Ranch Hand

Joined: Nov 03, 2000
Posts: 46
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?
John Wetherbie

Joined: Apr 05, 2000
Posts: 1449
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.

The only reason for time is so that everything doesn't happen all at once.
- Buckaroo Banzai
rupa agarwal

Joined: Nov 21, 2000
Posts: 24
hi there
i am also trying to develop ashopping cart ,but i am not usin servlets here i am just using beans ans jsp,and html and javascript.are u using servlets in ur shopping cart.
plz do reply
I agree. Here's the link:
subject: Designing applications using JSP, Beans and Servlets and HTML ??
jQuery in Action, 3rd edition