Results 1 to 7 of 7
- 05-11-2011, 07:18 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 5
- Rep Power
- 0
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. :)
- 05-12-2011, 09:37 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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
- 05-12-2011, 10:01 AM #3
Member
- Join Date
- Feb 2011
- Posts
- 5
- Rep Power
- 0
Thanks for the answer. There is one Controller Servlet or can be many Controller Servlets.
- 05-12-2011, 10:08 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
- 05-12-2011, 10:28 AM #5
Member
- Join Date
- Feb 2011
- Posts
- 5
- Rep Power
- 0
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?
- 05-12-2011, 12:20 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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).
- 05-14-2011, 08:26 AM #7
Member
- Join Date
- Feb 2011
- Posts
- 4
- Rep Power
- 0
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
-
Building GUI
By alacn in forum New To JavaReplies: 7Last Post: 06-17-2010, 04:32 AM -
Copy Default table model to another default table model?
By greatmajestics in forum AWT / SwingReplies: 2Last Post: 04-28-2010, 04:08 PM -
Building web application
By Assaf A in forum Advanced JavaReplies: 3Last Post: 01-27-2010, 08:07 PM -
How to download website (Get all link in website)
By finalmem in forum Advanced JavaReplies: 0Last Post: 11-12-2008, 08:43 AM -
building a house
By dc2acgsr99 in forum Java AppletsReplies: 4Last Post: 03-07-2008, 11:18 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks