nerdexam
Oracle

1Z0-900 · Question #48

You created two filters for your web application by using the @WebFilter annotation, one for authorization and the other for narrowing results by the provided search criteri

The correct answer is A. setting the priority attribute of the @WebFilter annotation for each of the filters. Option A is correct because when filters are declared via @WebFilter, the priority attribute (an integer value) determines their execution sequence - a lower value means higher priority, so the authorization filter should be assigned a lower number than the search-filter…

Create Java Web Applications using Servlets

Question

You created two filters for your web application by using the @WebFilter annotation, one for authorization and the other for narrowing results by the provided search criteri

Options

  • Asetting the priority attribute of the @WebFilter annotation for each of the filters
  • Bplacing the filter mapping elements in the required order in the web.xml deployment descriptor
  • Cplacing @WebFilterMapping annotations in the required order
  • Dspecifying the filter precedence order by using the @Priority annotation

How the community answered

(40 responses)
  • A
    83% (33)
  • B
    10% (4)
  • C
    5% (2)
  • D
    3% (1)

Explanation

Option A is correct because when filters are declared via @WebFilter, the priority attribute (an integer value) determines their execution sequence - a lower value means higher priority, so the authorization filter should be assigned a lower number than the search-filter. Option B is a trap: <filter-mapping> order in web.xml controls filter ordering only when filters are registered there; mixing @WebFilter-annotated filters with web.xml mapping entries for the sole purpose of ordering is not the intended mechanism and does not reliably reorder annotation-declared filters. Option C is wrong because @WebFilterMapping is a fictitious annotation - no such type exists in the Java EE/Jakarta EE Servlet API. Option D (@Priority) is a CDI-specific annotation used to order interceptors and alternatives, not servlet filters; applying it to a filter class has no effect on filter chain ordering.

Memory tip: Think "annotation-declared → annotation-ordered" - if you created the filter with @WebFilter, you control its order within that same annotation using priority. If the filter lived in web.xml, you'd use web.xml element order instead.

Topics

#@WebFilter annotation#Filter priority#Servlet filters#Filter execution order

Community Discussion

No community discussion yet for this question.

Full 1Z0-900 Practice