Results 1 to 7 of 7
  1. #1
    jprog is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default Building website according to the MVC model

    Hi, guys

    i created a website, but the presentation and the business logic aren't separated. In the jsp pages there is a connection to the database and retrieving data from the database.
    What will be the structure of my site according to the MVC model.

    JSP->ControllerServlet1->Bean1
    JSP->ControllerServlet2->Bean2
    JSP->ControllerServlet3->Bean3

    or something else.

    If you have more information about MVC model i will be appreciate. :)

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default

    The client makes calls to your server.
    These calls are handled by Servlets, which will generally make calls to a business layer. Servlets should simply control the flow, that is receive request, farm them off to a service layer, then forward to a suitable JSP when that service has finished its job.

    So it's:
    Java Code:
    Client -> Servlet -> Business Layer
                      -> JSP -> Client

  3. #3
    jprog is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default

    Thanks for the answer. There is one Controller Servlet or can be many Controller Servlets.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default

    Many.
    It's easier to break up the work that way, and to test individual bits of functionality.
    I click button X on the front end, that fires a call to servlet X on the back end. Button Y calls servlet Y.

    If there's a set of closely related operations then you might stick them in one Servlet, but I personally rarely see the advantage in that.

  5. #5
    jprog is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default

    In my case i'm using web.xml to store database parameters(driver, server, username, password, port). I have a servlet for retrieving parameters from the web.xml, model class which makes connection to the database and close the connection. And beans for every query to the database. Is this the right way?

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default

    Your model should know nothing about the database.
    There will be a database layer, essentially a set of DAOs, which will do the persisting.

    I'd stick the parameters in a properties file myself, which the database layer will then look at. Again, the servlet should know nothing about any databases. It should pass control into a business layer that then actually does the processing.

    Java Code:
    Client -> Servlet -> Service class (does the processing) -> calls DAOs (does the database interaction).

  7. #7
    cld71 is offline Member
    Join Date
    Feb 2011
    Posts
    4
    Rep Power
    0

    Default

    You can also use filters and listeners to do your business layer, and pass the data through the application, session, or request scope attributes to your servlet or JSP pages.

    Client -> Servlet/JSP -> Filter -> Filter -> ... -> Listener -> DAO -> Database

    Just remember you must declare the JSP with as a servlet in your web.xml file in order to be able to use a filter, because of the filter mappings.

Similar Threads

  1. Building GUI
    By alacn in forum New To Java
    Replies: 7
    Last Post: 06-17-2010, 04:32 AM
  2. Copy Default table model to another default table model?
    By greatmajestics in forum AWT / Swing
    Replies: 2
    Last Post: 04-28-2010, 04:08 PM
  3. Building web application
    By Assaf A in forum Advanced Java
    Replies: 3
    Last Post: 01-27-2010, 08:07 PM
  4. How to download website (Get all link in website)
    By finalmem in forum Advanced Java
    Replies: 0
    Last Post: 11-12-2008, 08:43 AM
  5. building a house
    By dc2acgsr99 in forum Java Applets
    Replies: 4
    Last Post: 03-07-2008, 11:18 PM

Posting Permissions

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