Results 1 to 7 of 7
  1. #1
    dush_gos is offline Member
    Join Date
    Jul 2010
    Posts
    3
    Rep Power
    0

    Default mvc using servlets and jsp

    I have heard a lot about mvc that how helpful it is. Please explain how can a servlet be used as a controller? Are all database connections reqd for the application opened only on the controller servlet? Can any other jsp page or servlet not be used for receiving data from db?
    How does a controller servlet handle all user requests?
    If I am not able to explain what I want to know then please explain the process of building a webapp using mvc with servlets, jsp's and java beans in a step wise manner. I'd like to thank you all in advance.

  2. #2
    raji0388 is offline Member
    Join Date
    Jul 2010
    Posts
    1
    Rep Power
    0

    Default

    hi

    MVC actually stands for the model view controller ,In MVC pattern 1 model is held in the bean class ,view and the control operation done by the JSP pages alone in sense the JSP pages are capable of fetching the data from the DB and displaying it in the web page via a jsp .

    MVC -II model 2 ,It defines the way that the view alone done by the JSP ,display the details in web page via the JSP on the presentation Logic is implemented in the JSP ,

    for instance a JSP page calls the servlet via a form action method="Servlet name"

    then control passed in the servlet (controller) ,the bean class gets the data from the DB ,then its passed to the servlet which in turns calls the jsp to display the record via a session .

  3. #3
    dush_gos is offline Member
    Join Date
    Jul 2010
    Posts
    3
    Rep Power
    0

    Default

    Hi raji0388, thanks for replying so quickly. You said that the bean class gets the data from db. What if we want to display an entire table from the database, how would we store this data in the bean. I think our bean will then need to have as data members all the columns in the db table. Then would we make arrays of these been objects to store 1 row as 1 bean object?
    Also for every SQL query that we use to retrieve some data to be shown as it is to the user, would we have to make a bean class? :confused:
    A response from raji0388 or any one else would be highly appreciated.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,792
    Rep Power
    19

    Default

    Usually it would be a Data Acces Object (DAO) that does the work with the database, and returns you your bean (or array of beans) which are then laid out in a view by the JSP.

    Your bean model will usually not know how it is stored, or if it is stored. That's the job of the persistence layer (the DAO).

    Normally your servlet would pass off the work it has to do to a business layer (a business object of some sort), which then does whatever processing is needed, including calling DAOs, and then passes the result back to the servlet which then decides which JSP it should go to. So the servlet controls which business logic is called and, based on the result of that logic, then decides which view (JSP) to show.

  5. #5
    dush_gos is offline Member
    Join Date
    Jul 2010
    Posts
    3
    Rep Power
    0

    Default

    Thanks a lot for your reply Tolls, please tell me a link to some application that uses mvc with servlets, jsp and javabeans .
    Thanks in advance.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,792
    Rep Power
    19

    Default

    Is google down?
    What I wrote is from my work, so I don't have any links.

  7. #7
    flyfisherman is offline Member
    Join Date
    Mar 2010
    Posts
    26
    Rep Power
    0

    Default

    Tolls already told you the answer and I would like to recommend Murach's Java Servlets and JSP.

    The book is great

Similar Threads

  1. servlets in eclipse
    By simo_mon in forum Java Servlet
    Replies: 1
    Last Post: 10-04-2009, 11:30 AM
  2. servlets
    By priyacvr in forum Java Servlet
    Replies: 2
    Last Post: 09-28-2009, 07:43 AM
  3. Servlets
    By javahelp00 in forum New To Java
    Replies: 1
    Last Post: 02-28-2009, 06:28 PM
  4. servlets or jsp
    By krishnapal in forum Advanced Java
    Replies: 1
    Last Post: 12-13-2007, 02:31 PM
  5. Servlets
    By nagaroopanandha in forum Advanced Java
    Replies: 1
    Last Post: 08-07-2007, 02:09 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •