• 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

Is this MVC?

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I posted this in the design patterns forum a couple of days ago but got no reply. Perhaps put it in the wrong forum?

"I am developing a sample web application using the Model view controller pattern. I have a handlerServlet which I use to pass control to other servlets. Those servlets contain some of my business logic and in turn pass control to JSPs for display. Like depicted below

handlerServLet --> Task specific servlets --> JSPs (results / user inputs)

Now, based on certain user inputs I need to forward the user from the JSPs to some other servlets. I reckon this is going to get me into a bit of a mess.

Is it alright that I pass the control back to the handlerServlet and then go to the respective servlet from there? On the other hand, isn't it a bit of an extra overhead when the control can go direct from the JSP to another servlet?

This is the dilemma I am facing. Can someone advise?

Also should I make a servlet for each business logic task that I want to perform? Or should I just have a new method in my handlerServlet?

Thanks. "

Can someone pls also explain whether MVC requires that you have a single controller servlet. What if it becomes too unweildy? Can we have multiple controller servlets co-ordinating?

Thanks again.
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
very nice explaination buddy. i liked the way you put your problem.

anyways. it is not necessary in MVC that you have to have one servlet only. we can use task/module specific servlets. in MVC the Model(your business logic) and your View(presentation tier) should not interact with each other directly. they should go through a controller. a Controller could be any servlet.

But here, in your previous message, i can not hear anything about the Model. how you are implementing your model. usually, if not using something like ejb or something, our simple java classes work as a Model.

JSP ---> servlet(could be any, if many) ----> java class (business logic)

and then

java class (business logic) ----> servlet(could be any, if many) ---> JSP

I hope it will give you some idea about how MVC works.
 
Dinesh Kumar
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Adeel.

I also have some simple classes (models) that are carrying out some tasks. I am calling the methods in these classes from the servlets based on certain conditions that I check in the servlets. So if a condition is tru the servlet calls method "a" in the class else it calls method "b" etc.

My only worry was I was ending up with quite a few servlets (about 10) and I thought this may not be correct.

Thanks for clearing this.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why are you thinking like that. it is OK. sometimes we use only one servlet as a controller in the whole app.
 
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, Adeel...

Can i get a model code for the MVC2 architecture. Jsut to get the full taste of it?

Any code, simple, like one for each component, in a model, View and controller.....

This will really be helpful.

Thanks man.....

Cheers,
Swamy
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah i have some code but its proprietry. Dont have something of my own. So it is impossible to send or disclose it anyway.

but you can get the simple example codes easily from any MVC2 tutorials. if we look at struts framework, it reflects MVC architecture + Command Pattern. And most of the Servlet and JSP books talk about design patterns, primarily MVC2.

regards
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic