Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Best practice controller implementation for different actions

 
Harshana Dias
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose I have actions like edit delete and update. If so what is the best practice to implement the controllers. Is it like one servlet map to different actions or separate servlets for each action?

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34378
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One servlet is much more common. That's how most web frameworks work as well. One servlet to delegate to the proper class that does the work. You want to avoid having non controller login in that servlet though. Your logic should be in other classes you delegate to. And there would be one of those per action.
 
Harshana Dias
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote: Your logic should be in other classes you delegate to. And there would be one of those per action.


Those are the model classed in MVC architecture know.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harshana Dias wrote:
Jeanne Boyarsky wrote: Your logic should be in other classes you delegate to. And there would be one of those per action.


Those are the model classed in MVC architecture know.


No, that's not what's she's talking about. Perhaps this article can help.
 
Piyush Mangal
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is fine to have one controller for both delete and update action as long as they can be functionally grouped. Even frameworks like Struts and Spring MVC had DispatchAction and MultiActionController for the same usecase.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34378
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Piyush Mangal wrote:It is fine to have one controller for both delete and update action as long as they can be functionally grouped. Even frameworks like Struts and Spring MVC had DispatchAction and MultiActionController for the same usecase.

That's true. The original poster didn't sound that far down in design so I answered differently.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic