• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

MVS Problem?

 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I am learning JSP and Servlets. I am trying to do a small project in the area I have learned so far. Simply I am trying to do a MVC thing.

I am just adding/deleting/updating the customer registration details to the Database.
Now the section I havint the doubt.
I am using JSP for view that is, I am creating the form in the Customer.jsp (for example: Customer ID(int), Customer Name(char), Customer Age(int), Customer DOB(date))

I am using JavaBean for setting and getting the properties in Customer.java. (for example:
private String customer_id,customer_name,customer_age and customer_dob;
And getter and setter method.


Now whether the database connection and all other updating thing to the database should be kept at Servlets (i.e., Customer_Ser.java) or at JavaBean(i.e., Customer.java)

I have seen the database connection in JSP, Servlet and Javabean. I know it is very bad thing to do any database thing in JSP. But, which one is best to use the database connection ? in Servlet or Java (Javabean).

Is there any situation to use the database connection in JSP.

If possible, any sample coding(I have written the coding, but I want to know, which one is having better performance and also see how the real appln have coded in the MVC) for just adding the details to the database in MVC Pattern.

Thanks in advance,
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are following the MVC pattern, the DB connaction should definitely not be in the JSP or servlet. Usually, that will be part of the model/business logic. Enterprise level applications would even separate it further by putting it in it�s own class using the DAO pattern.
 
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No servlet, no javabean, for database connection use separate class(classes). Maybe take a look at some DB related patterns as DAO for example.
 
Niyas Ahmed Sheikh
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for your reply.

So I can say that JSP only for view that is for presentation like GUI(forms).
Servlets for controller.
And what about JavaBeans? it is only for Property only?
can i get any sample codings or example in website for Model-View-Controller
Even JavaBean also a Java file with some speical properties. Why you are telling not to use database connection in JavaBean.

If I am using separated class for database connection, what will be the use. In that case for example, for registration of the customer details in the database requires the following files. (pls, at this moment EJB is far away from my learning)

Customer.jsp - For Forms
Customer_JavaBean.java- For getting and setting properties
Customer_Servlet.java - For controlling?(Having doubt in this file of his
role
Customer_DB.java - For database connection

How these four will interact. I want the example thing for the above mentioned thing. If possible, pls provide the link. I had searched in google, but I am getting some complex mvc with EJB.

Also suggest, the above four files are mandatory for fulfilling a Good MVC Pattern.
 
Niyas Ahmed Sheikh
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can I get the sample or example codings in the DAO Pattern. I have searched in google. Not getting any useful/related to my problem. Just I want to add the customer/student details in the database by using MVS, or as the group member told as DAO. How to use it, any sample or example coding will be available.
 
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html
 
reply
    Bookmark Topic Watch Topic
  • New Topic