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 Servlet as Front Controller Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet as Front Controller" Watch "Servlet as Front Controller" New topic
Author

Servlet as Front Controller

Lynn Haley
Greenhorn

Joined: Jun 13, 2009
Posts: 20
Can someone please explain to me the best practices of using the Front Controller pattern?

Should I be using these one per use case?
I have seen some applications where this is the only point of entry and it is quite large.

Maybe the Servlet should be calling a separate object, rather than acting as control?
I am learning Struts and I see that you put a lot into one class.
Does this not grow to be too big?

Thanks,
Lynn
ujjwal soni
Ranch Hand

Joined: Mar 28, 2007
Posts: 403
Hi,

Here's one cool link about Front Controller.

http://java.sun.com/blueprints/corej2eepatterns/Patterns/FrontController.html


Cheers!!!
Ujjwal B Soni <baroda, gujarat, india> <+919909981973>
"Helping hands are better than praying lips......"
Lynn Haley
Greenhorn

Joined: Jun 13, 2009
Posts: 20
Thank you!

It appears if I want to support multiple View types, JSP, XML, PDF, then splitting the Front Controller into
two pieces:

- The controller for handling all requests in the system.

and

- A dispatcher is responsible for view management and navigation

What is a best practice for knowing when the dispatcher should be part of the controller, and when they should be separated?

If I am always working with JSPs should I just have one object?

What if I get a ton of requests, should I have multiple controllers?

Thanks for your thoughts!

Lynn
ujjwal soni
Ranch Hand

Joined: Mar 28, 2007
Posts: 403
Hi,

Yes, correct !!!

What is a best practice for knowing when the dispatcher should be part of the controller, and when they should be separated?

--It depends on functionality and importance

If I am always working with JSPs should I just have one object?

--Yes

What if I get a ton of requests, should I have multiple controllers?

--Yes you can use multiple controllers



See, this is what i am doing for one of my document processing system

Front controller gets requests for pdf, doc, ppt...

It recognizes the request and pass on to other controllers like for pdf, its http://localhostL8080/pdfController?type=PDF

It recognizes the request and pass on to other controllers like for doc, its http://localhostL8080/docController?type=DOC

It recognizes the request and pass on to other controllers like for ppt, its http://localhostL8080/pptController?type=PPT

Lynn Haley
Greenhorn

Joined: Jun 13, 2009
Posts: 20
great example, thank you!

Are you writing all the code yourself, or using a framework?

Im trying to see how this might fit in with Struts or Spring MVC.

Thanks,

Lynn
ujjwal soni
Ranch Hand

Joined: Mar 28, 2007
Posts: 403
Hi,

I am using struts framework...
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41583
    
  54
An excellent article on that was published here on the ranch: http://www.javaranch.com/journal/200603/Journal200603.jsp#a5


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet as Front Controller