This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet as Front Controller

 
Lynn Haley
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Here's one cool link about Front Controller.

http://java.sun.com/blueprints/corej2eepatterns/Patterns/FrontController.html
 
Lynn Haley
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using struts framework...
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An excellent article on that was published here on the ranch: http://www.javaranch.com/journal/200603/Journal200603.jsp#a5
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic