wood burning stoves 2.0*
The moose likes Servlets and the fly likes FrontController example Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "FrontController example" Watch "FrontController example" New topic
Author

FrontController example

Bechir Bejaoui
Greenhorn

Joined: Feb 06, 2013
Posts: 7
Hi folks

I'm new in java so bear with me please, I'm discovering the FrontController for the first time. In some books I read that the FrotController is used to avoid developping a controller for each view that's fine however I can't understand how one controller can call multiple views at a time, I tried to follow some few examples however I get stucked. I need a clear step by step example of Frontcontroller servlet implementation especially for login senario like

index.jsp ---> login.jsp -->if(logged)-->welcome.jsp
^ -->if(!logged)-->Notlogged.jsp--

-----------------------------------------
And I need to know how to make the mapping configuration

Thank you
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60732
    
  65

Each view still has its own controller -- the purpose of the Front Controller is to dispatch to those various controllers. This prevents having to map a servlet for each and every controller; you have only one servlet that needs mapping, and it figures out which controller to dispatch or forward to.

I developed a micro-framework that is essentially a glorified Front Controller implementation called FrontMan. It is open source and you can read its documentation and look at its code to see how it operates.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

I love @bear's FrontMan. I've been using it for years, maybe four or more. Its great, and Bear supports it here. Highly recommended.
Bechir Bejaoui
Greenhorn

Joined: Feb 06, 2013
Posts: 7
Bear Bibeault wrote:Each view still has its own controller -- the purpose of the Front Controller is to dispatch to those various controllers. This prevents having to map a servlet for each and every controller; you have only one servlet that needs mapping, and it figures out which controller to dispatch or forward to.

I developed a micro-framework that is essentially a glorified Front Controller implementation called FrontMan. It is open source and you can read its documentation and look at its code to see how it operates.


Thank you I appreciate that, one last question when I use Front controller along with the view helper(Service to worker) how to pass parameters from the frontcontroller to the view helper and thank you again
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60732
    
  65

As I have no idea about the nature of your "view helpers", it's rather hard to say.
Bechir Bejaoui
Greenhorn

Joined: Feb 06, 2013
Posts: 7
Bear Bibeault wrote:As I have no idea about the nature of your "view helpers", it's rather hard to say.


I will follow the Custom tag strategy for implementing those view helpers, instead of implementing them as Value Beans. The custom tags need some upfront works but they bring an elegant solution since you just need to add tags to the view instead of adding scriptlets (
when you implement value beans helpers).

What I really can't figure out is how to pass parameters form the front controller to a given custom tag helper since I'm new to the state management under java.

If there is any other idea of implementing the Service to Worker pattern using cutom tags as veiw helpers, they re welcome iof corse

Thank you
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60732
    
  65

Parameters are available on the request. So if the request is still available (as the result of a forward, for example) the params will also be available. Otherwise, you'll need to capture them and pass them along as subsequent params or perhaps using the session temporarily.

Generally, I find that if you need the entire set of parameters from a previous submission in the page controller for the next page, there's a design flaw.
 
Don't get me started about those stupid light bulbs.
 
subject: FrontController example
 
Similar Threads
class diagram & component diagram
Need Clarification on packaging
Confused - MVC, JSP, Servlet interaction
UML sequence diagram help
New Article: Scriptless JSP Pages: The Front Man