jQuery in Action, 3rd edition
The moose likes Servlets and the fly likes Best practice controller implementation for different actions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Best practice controller implementation for different actions" Watch "Best practice controller implementation for different actions" New topic
Author

Best practice controller implementation for different actions

Harshana Dias
Ranch Hand

Joined: Jun 11, 2007
Posts: 330
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

Joined: May 26, 2003
Posts: 32495
    
214

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.


[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Harshana Dias
Ranch Hand

Joined: Jun 11, 2007
Posts: 330
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

Joined: Jan 10, 2002
Posts: 63221
    
  69

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Piyush Mangal
Ranch Hand

Joined: Jan 22, 2007
Posts: 196
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

Joined: May 26, 2003
Posts: 32495
    
214

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.
 
Have you checked out Aspose?
 
subject: Best practice controller implementation for different actions
 
It's not a secret anymore!