Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFS&JSP - patterns?

 
Richard Quist
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The blurb about the book on Amazon mentions "Learn to ... and even use some server-side design patterns."

What patterns are discussed, and how much detail?

Thanks
 
Bert Bates
author
Sheriff
Posts: 8900
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Richard,

The last two chapters (and about half a chapter in the beginning of the book), are devoted to patterns.

Near the begining of the book we do an intro to web-MVC. The penultimate chapter is all about filters. This chapter does double duty, giving you an insight into the Intercepting Filter questions you might experience on the exam, and also giving you a good foundation in how this pattern is applied to the implementation in the Servlet spec.

The last chapter is all about J2EE patterns, Struts, and MVC. The J2EE patterns we cover are: Business Delegate, Service Locator, Transfer Object, and Front Controller.

So the exam objectives mention 6 patterns. MVC isn't considered by some to be an official, card-carrying, J2EE pattern, but it's obviously important. The other five ARE J2EE patterns, although given the Servlets application of filters it would be rare to apply your own hand-rolled intercepting filter.

We provide a quick overview to Struts - remember it's NOT on the exam, but we thought it important enough to cover anyway (and by "cover" I mean "get your feet wet").

- Bert

p.s. We get into a good level of detail on coding filters (with 2 code examples, a request filter and a response filter), and we provide a complete (albiet tiny), Struts application, in code. The other patterns are described at a conceptual level, but I'd say it's a "detailed, conceptual" conversation
[ October 19, 2004: Message edited by: Bert Bates ]
 
Richard Quist
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excellent!

Thank you.
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bert,

By talking about the pattern issue, I sometimes feel confused about MVC and FrontController, as seems both of them define a controller to receive the request, and then dispatch to the required services, as well as the presentation layer.

Could you explain a bit on the major difference? Some books said FrontController is the control of the workflow, while MVC does not, is that really true?

Nick
 
Bryan Basham
author
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nick,

I'll tackle this one...

Originally posted by Nicholas Cheung:
By talking about the pattern issue, I sometimes feel confused about MVC and FrontController, as seems both of them define a controller to receive the request, and then dispatch to the required services, as well as the presentation layer.

Could you explain a bit on the major difference? Some books said FrontController is the control of the workflow, while MVC does not, is that really true?


First of all, MVC does not imply only one controller; in fact, quite the opposite. There is usually one controller object for each action that your user interface must process. In a webapp, this means that you need one application controller (either a servlet in a non-Struts webapp or a Struts Action subclass) for each *type* of HTTP request.

A FrontController (FC) has nothing to do with MVC and this pattern can be applied to a non-MVC webapp as well as an MVC webapp. An FC is what is known as an infrastructure controller.

Also check out my reply in: Can we have more than one controller in MVC pattern?

-Bryan
 
Colin Fletcher
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the link to the Spec from Sun.
 
Roger Yates
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice diagram, duly bookmarked
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bryan,

That is to say, if I use FC, there should be only 1 Servlet that controls the workflow, while this FC knows everything, and be able to deligate the requests to different *sub* controller to continue the process?

Nick
 
Bryan Basham
author
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nicholas Cheung:
That is to say, if I use FC, there should be only 1 Servlet that controls the workflow, while this FC knows everything, and be able to deligate the requests to different *sub* controller to continue the process?


There are many ways to implement the FC pattern. You can use a servlet (as is done in Struts with the ActionServlet) or you can use a filter or some other bizarre mechanism you might concoct. However, the servlet-FC implementation is the easiest to understand and so it is the most common.

The hard part of the FC pattern relates to the second part of you question: "while the FC knows everything..." In reality, you do not want the FC to know anything about the application logic/controllers. So, what most FC impls do is give you some configuration file (such as the struts-config.xml file in Struts) that allows the FC impl to be completely generic. The "sub controllers" (or more accurately, "application controllers") are declared in the configuration file that the FC uses to dispatch each request to the appropriate application controller.

Make sense?

-Bryan
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, we may need to define our own configuration for FC, including its own details, as well as the subelements for some other controllers, init them when needed by passing in the subelements configuration?

Nick
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic