aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes MVC Achitecture Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "MVC Achitecture" Watch "MVC Achitecture" New topic
Author

MVC Achitecture

Abhishek Asthana
Ranch Hand

Joined: Sep 08, 2004
Posts: 146
Hi,
I am having a little doubt about design of my Application and I need your help.
I am planning to use MVC architecture and I am thinking of having an EJB/Servlet/JSP trio for each page. Actually I want to display data from database on each page. For this I am thinking of using a different servlet passing arguments to its respective EJB which accesses database and sends the results back. But my Instructor says that there should be one servlet that should act as controller.
Please tell me what should I do? Is it such that in MVC there ought to be only one servlet throughout?
Abhishek
Malli Raman
Ranch Hand

Joined: Nov 07, 2001
Posts: 312
Originally posted by Abhishek Asthana:
Hi,
I am having a little doubt about design of my Application and I need your help.
I am planning to use MVC architecture and I am thinking of having an EJB/Servlet/JSP trio for each page. Actually I want to display data from database on each page. For this I am thinking of using a different servlet passing arguments to its respective EJB which accesses database and sends the results back. But my Instructor says that there should be one servlet that should act as controller.
Please tell me what should I do? Is it such that in MVC there ought to be only one servlet throughout?
Abhishek


There is one advantage of using single servlet instead of multi servlets is that you don't need repeat the same logic in all servlets. Use servlet mapping for implementing this.
Abhishek Asthana
Ranch Hand

Joined: Sep 08, 2004
Posts: 146
Can you please tell me about servlet mapping? I have never used this thing.
Thanks.
Abhishek.
kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1382
Here EJB is your Model of MVC?
Inderveer singh
Greenhorn

Joined: Feb 08, 2005
Posts: 15
Just look into struts framework. i think it will solve all your problems.
Struts uses MVC Architechture only and its framework reduces the task by providing its servelet controller.and actionform class etc.

visit http://struts.apache.org/
for more info.
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Yes Abhishek, you instructor is right: it must be a unique servlets that acts like the controller. As you already heard Struts is a very popular (although far from being perfect) framework that could help you implementing an MVC paradigm. But I got the feeling this is only a training project and you won�t like using other frameworks.
From what I understood your architecture looks like this:

JSP1 -> Servlet1 -> EJB1
JSP2 -> Servlet2 -> EJB2
JSP3-> Servlet3 -> EJB3

Having a controller will make it look something like this:

JSP1 -> Controller Servlet -> Servlet1 -> EJB1
JSP2 -> Controller Servlet -> Servlet2 -> EJB2
JSP3 -> Controller Servlet -> Servlet3 -> EJB3

(Here the Controller Servlet is one and the same instance for every scenario). You might ask then why would you need the Servlet1, Servlet2 and Servlet3 anyway? Finally you might like changing your architecture like this:

JSP1 -> Controller Servlet -> EJB1
JSP2 -> Controller Servlet -> EJB2
JSP3 -> Controller Servlet -> EJB3

The ultimate challenge will be how to design the way your controller servlet locates the EJBs, invokes business methods and returns the result back to the clients. Having a huge servlet that implements all this logic is definitely something that you�d like to avoid. Finally you might consider developing your own framework of plain java classes that do the job. You can develop and test the framework independently of your struts controller, etc.


I think, therefore I exist -- Rene Descartes
Dilip kumar
Ranch Hand

Joined: Oct 16, 2000
Posts: 360
Hi,

Since we are discussing about architecture I thought I will ask the question for which I never got the clear answer. What I understood is not all MVC based application use EJBs. What I would like to know is under what requirements you use EJB . I really appreciate any answers.

Thanks
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi Dilip,


What I would like to know is under what requirements you use EJB.

Well this is no easy question and there is no straight answer. It depends upon your project requirement, human power, company infrastructure, etc. Try this link it might provide you with several good ideas about when to use EJBs and not to use them.

http://www-106.ibm.com/developerworks/library/ibm-ejb

Regards.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MVC Achitecture