File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
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: 327
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: 31057
    
232

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Harshana Dias
Ranch Hand

Joined: Jun 11, 2007
Posts: 327
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: 61762
    
  67

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: 31057
    
232

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Best practice controller implementation for different actions