• 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

MVC Achitecture

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you please tell me about servlet mapping? I have never used this thing.
Thanks.
Abhishek.
 
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here EJB is your Model of MVC?
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic