aspose file tools*
The moose likes JSP and the fly likes Model 2 Front controller? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Model 2 Front controller?" Watch "Model 2 Front controller?" New topic
Author

Model 2 Front controller?

Andrew Mcmurray
Ranch Hand

Joined: Sep 24, 2005
Posts: 188
Hi all

I read Bear's article "Scriptless JSP Pages: The Front Man" and found it very informative. I pretty much understood what was going on, but just wanted to make sure this makes sense using to you guys. So basically in a Model 2 all requests come into the front controller and then the controller delegates out to certain command classes based on a configuration. I was a little confused as to where this config is kept? I was thinking I could do something like this. Let me know if this sounds correct?

Say I had a jsp and you could either view, update, delete, or create something. Could I just set a request parameter called method send the request to the front controller, have a switch on the method parameter, and then create whatever command class I needed to delegate out to based on the method name? For example if I passed ?method=delete id=1 then the front controller could created a DeleteCommand class do the deletion and then redirect to the view controller which would then fwd back to the jsp? Does this make sense?

Thanks,

AMD
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3859

Andrew Mcmurray wrote:... Say I had a jsp and you could either view, update, delete, or create something. Could I just set a request parameter called method send the request to the front controller, have a switch on the method parameter, and then create whatever command class I needed to delegate out to based on the method name? For example if I passed ?method=delete id=1 then the front controller could created a DeleteCommand class do the deletion and then redirect to the view controller which would then fwd back to the jsp? Does this make sense?

Yep sounds correct, make sure your view controller prepares the JSP(s) accordingly. You may want to check for frameworks like Struts, Spring MVC etc... to see how these are implemented in real world.

[Edit]Corrected a misspelled word[/Edit]


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Andrew Mcmurray wrote:I read Bear's article "Scriptless JSP Pages: The Front Man" and found it very informative.
Thank you!

So basically in a Model 2 all requests come into the front controller and then the controller delegates out to certain command classes based on a configuration.

Sort of. A Front Controller isn't absolutely necessary to adhere to Model 2. All that matters is that each page has a controller that prepares the page, rather than trying to do this with Java code in the JSPs themselves. These controllers can each be individual servlets. But that gets messy really fast. The Front Controller helps to tame this messiness.

I was a little confused as to where this config is kept?
It depends upon the Front Controller implementation. My FrontMan implementation uses a lot of "configuration by convention", along with annotations, and (as a last resort) property files. Others might use XML or other configuration mechanisms.

Take a look at FrontMan (link in my sig) if you'd like to see a simple implementation without all the bells and whistles (and complexity) of behemoth frameworks like Struts or SpringMVC.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Andrew Mcmurray
Ranch Hand

Joined: Sep 24, 2005
Posts: 188
Thanks guys! Bear, I will check out your Front Man impl. I need something without all the bells and whistles bc I am not sure how accepting my new project will be of me if I start demanding we need to implement a new framework The Web app is not too too big, so I think I can kill two birds with one stone. Make the jsps more scriptless and move at least the new code to more of a Model 2.

Thanks,

AMD
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3859

Andrew Mcmurray wrote:... and whistles bc I am not sure...

Please UseRealWords when posting as it might confuse the reader
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4659
    
    5

Andrew Mcmurray wrote:Thanks guys! Bear, I will check out your Front Man impl.

I love Bear's FrontMan. Its great.
Mike Heffelfinger
Greenhorn

Joined: Jan 11, 2010
Posts: 13

I like Front Man too :thumbup: ... simple and powerful. I wrote a couple of articles on using it in simple applications.

Sample Hello World Front Man JAVA web application
Example Java web application using Google App Engine with Front Man
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Model 2 Front controller?