• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFSJ 2 ed. Final mock exam 65 question

 
Kiril Nugmanov
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A programmer is creating a filter for a Java EE web application. Given the following code:

What change(s) are necessary to create a valid filter? (Choose all that apply.)
A. No changes are necessary.
B. A destroy() method must be added.
C. The doFilter() method’s body must be changed.
D. The init() method’s signature must be changed.
E. The doFilter() method’s arguments must be changed.
F. The doFilter() method’s exceptions must be changed.

Book marks B C D and E as correct but as my opinion C is incorrect - filters can block request, make redirects ans dispatches. Call of chain.doFilter() method is not necessary.

Am I correct?
 
Chinmaya Chowdary
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kiril.
A programmer is creating a filter for a Java EE web application.

I think, the body must be changed. Here the question is for a Java EE web application. This means, the application deals with http protocol. Thats why, the body must include,
 
Kiril Nugmanov
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chinmaya Chowdary,

But Your described actions are not mandatory. Filter can easily deals with ServletRequest and ServletResponse - everything depends on the logic that will be placed in that filter.

But as example of blocking filter:


just outputs to the console message(that can be just commented in the filter) and it still will be working and correct - if purpose of it - block requests.
 
Chinmaya Chowdary
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kiril. If we don't use the following code in doFilter(), the filter is valid one and will run without any problems.

Here the question is
A programmer is creating a filter for a Java EE web application.

It means the application deals with http protocol. So we need to change the code inside doFilter() method inorder to deal with.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic