File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

filter question

 
Sandhya Lever
Ranch Hand
Posts: 90
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which is true?
1. The init method for a filter is called the first time the servlet mapped to the filter is invoked.
2.A filer defined for a servlet must always forward control to the next resource in the filter chain.
3.Filters associated with a servlet are applied in the order in they appear in the DD.
4.If the init method throws unavailable exception the container will make no further attempt to execute it.

There is one right answer but I feel 2,3,4 are right.
 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I am giving my opinion on the various choices:

2. A filer defined for a servlet must always forward control to the next resource in the filter chain

This is not always true. If you do not call doFilter method on the filter chain(block further request processing) , then the next resource is not called.

3. Filters associated with a servlet are applied in the order in they appear in the DD.

This might change if there is a <url-pattern> which matches the servlet you requested.

4. If the init method throws unavailable exception the container will make no further attempt to execute it

I guess this one should be correct.

cheers
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I feel 1 is correct. Because there is NO unavailable exception defined by filter's init method. ONLY servletException is defined.
 
Luis Torres
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I feel 1 is correct. Because there is NO unavailable exception defined by filter's init method. ONLY servletException is defined.


Although only ServletException is defined for filter's init method, UnavailableException extends from ServletException, so is legal throws an UnavailableException from init method.

3. Filters associated with a servlet are applied in the order in they appear in the DD.

This might change if there is a <url-pattern> which matches the servlet you requested.


La question is specific about Filters associated with servlet(through mapping between filter-name and servlet-name).In this case Filters are applied in the order in they appear in the DD.

So my guess is number 3.

But, I'm not sure about sentence 4.

"If the init method throws unavailable exception the container will make no further attempt to execute it."

Is true or false?

Thanks.
 
S Sravs
Ranch Hand
Posts: 85
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
according to me both 3 and 4 options are true
option 3:since the filter follows declartive control as per design patterns.
option 4:unavailable exception occurs in two conditions
A servlet or filter is permanently unavailable,a servlet might be configured incorrectly, or a filter's state may be corrupted
A servlet or filter is temporarily unavailable if it cannot handle requests momentarily due to some system-wide problem like there may be insufficient memory or disk storage to handle requests

this link may help
http://www.coderanch.com/t/171724/java-Web-Component-SCWCD/certification/Unavailable-Exception

Regards
Sravanthi
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic