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

Doubt on HFSJ Ch 13 mock ques #5.

 
Connie Ky Leung
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I got question 5 on chapter 13 wrong after reading HFJS twice. I wonder why one of the correct answers is A. The statement of choice A is "Filter is used to create request and response wrappers.". Answers at the back of the chapter indicate that explanation can be found on page 51 of servlet specfication. I read that page but did not spot any sentence that states that fact.

Can someone please help me clear my doubt?

Thanks and regards,

Connie Leung
 
Ken Young
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I came across the same question and wondered the same thing.

Option A: "Filters may be used to create request or response wrappers."
Option B: "Wrappers may be used to create request or response filters."

I picked option B (twice! >_< even though the answer is option A with the explanation "option B is incorrect because the terminology is reversed."

I picked option B because I thought a class that implements the Filter interface (the "request or response filter") uses/instantiates other wrapper classes in the doFilter() method, like the example on page 690. Doesn't that mean wrappers can be "used to create" request or response filters (option B)?

Now I read a few times more, I would choose option A if it means something like "I can use the Filter mechanism to pass wrappers for request/response objects to the servlet", hence filters can be "used to create" request or response wrappers.

Why is my first explanation incorrect?? Or am I just confused on the English here.....
 
Steven Colley
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guess is that we need to be simpler here.

Does not exist neither "request filter objects" nor "response Filter objects".
--> ""Wrappers may be used to create request or response filters.""

Filters can only create another mechanism to "decorate" real request and response objects, improving it before sending back to the client.

So Filters create "decorators objects" (wrapper classes) for doing this.
--> "Filters may be used to create request or response wrappers".

regards,
 
Connie Ky Leung
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for replying.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic