aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes filter question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "filter question" Watch "filter question" New topic
Author

filter question

Sandhya Lever
Ranch Hand

Joined: Aug 15, 2005
Posts: 90
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.


SCJP | SCWCD |SCBCD |SCDJWS |SCEA
Naresh Chaurasia
Ranch Hand

Joined: May 18, 2005
Posts: 356
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


SCJP 1.4, SCWCD1.4, OCA(1Z0-007)
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
I feel 1 is correct. Because there is NO unavailable exception defined by filter's init method. ONLY servletException is defined.


Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
Luis Torres
Greenhorn

Joined: May 02, 2008
Posts: 20
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.


SCJP5 90%
S Sravs
Ranch Hand

Joined: Feb 25, 2008
Posts: 85
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: filter question
 
Similar Threads
init method from a filter
a web container question
init method called twice!
WebFilter Annotation and servletNames attribute
Response Headers