• 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
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Trouble implementing front controller

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to replace web.xml with a servlet as a front controller. I first tried using a request dispatcher and found that I still needed everything delcared in web.xml, which I don't see the point of adding a controller if the user can just go around it using the web.xml declarations. I have seen another pattern a few times (following) but haven't seen definitions of "RequestHelper", "Command", or "ApplicationResources". Where do these come from?



Thanks!
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Command Pattern is one of my favorites for some reason. The interface for your commands requires a method execute(request,response). There could be any number of concrete commands that do different things in execute, maybe one per form or one per business function.

You can see your code sample getting a command object. We don't see how, but the helper gets us a command object that is appropriate for the inbound request. It might use a hidden field or parameter on the request to get a command from a map. We can imagine that every page has a hidden field called "cmd" and the login page has a value of "login", The helper gets us an instance of LoginCommand, and the LoginCommand authenticates the userid and password fields on the form. Finally the command returns the page we should go to next, which I'll assume is a JSP, and we dispatch off to that page.

This has replaced the web xml mapping of URLs to servlets with our own mapping of "cmd" values to commands.

I made something very much like this at work this year. I like the way it works very well. Struts and other frameworks use the same ideas, but you can make something simple in only a few lines.

Other questions: It looks like "application resource" is a thinly disguised anchor for global variables. That's a necessary evil some times.

The "page helper" is not doing much beyond finding the right command for you. If it really did nothing else, I'd call it a CommandFactory instead.

Does all of that sound fun?
 
Rob Lynn
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Loads of fun...thanks!!
 
reply
    Bookmark Topic Watch Topic
  • New Topic