Win a copy of Terraform in Action this week in the Cloud forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Design Question - Controllers

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've finally wrapped my head around the concept of using JSP for the view, a servlet for the controller, and POJOs for the model. I find myself routinely falling back into this pattern for my controller, which I totally fabricated in my head and I have no idea if it is good/bad/otherwise.

I basically define an enum in my servlet class called Action that contains values I expect to receive as a parameter. I attempt to match the request parameter stored in "action" to one of the enums. Then I enter a switch statement that switches on the enum values. Each case does whatever it needs to to the model and sets the url string for the dispatcher. At the end of the switch statement, I forward the request using the dispatcher.

Is this how a controller should work? Are there any good resources available on controller design/patterns/etc?
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not quite sure about patterns for controller but frameworks might help! I like struts (http://struts.apache.org) framework where all heavy duty controller work is already done. Then there are also other popular frameworks like Spring (http://www.springframework.org)
 
Sheriff
Posts: 67602
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are just looking for a simple implementation of a Front Controller, you might want to check out my FrontMan project (link below in my sig).
reply
    Bookmark Topic Watch Topic
  • New Topic