nerdexam
Oracle

1Z0-900 · Question #12

How do you specify a default error page in your web.xml file?

The correct answer is B. <error-page><error-code>*</error-code><location>/general-error.html</location></error-page>. Option B uses the correct <error-page> element defined in the Servlet specification, paired with <error-code></error-code> as a wildcard to catch all HTTP error codes, and <location> to specify the error page path - together these form a valid catch-all default error page…

Create Java Web Applications using Servlets

Question

How do you specify a default error page in your web.xml file?

Options

  • A<on-error><location>/general-error.html<location></on-error>
  • B<error-page><error-code>*</error-code><location>/general-error.html</location></error-page>
  • C<on-error><error-code>*</error-code><location>/general-error.html</location></on-error>
  • D<error-page><location>/general-error.html</location></error-page>

How the community answered

(40 responses)
  • A
    3% (1)
  • B
    90% (36)
  • C
    3% (1)
  • D
    5% (2)

Explanation

Option B uses the correct <error-page> element defined in the Servlet specification, paired with <error-code>*</error-code> as a wildcard to catch all HTTP error codes, and <location> to specify the error page path - together these form a valid catch-all default error page entry. Options A and C both use <on-error>, which is entirely fictional and not part of the web.xml DTD/schema - if you see <on-error> on an exam, eliminate it immediately. Option D is close but invalid because <error-page> requires either an <error-code> or <exception-type> child element to be well-formed per the spec; a bare <location> alone is insufficient.

Memory tip: Think "EPE-L" - <error-page> wraps either <error-code> or <exception-type>, then <location>. The wildcard * on the error code makes it the default. Any answer using <on-error> is a trap - that tag does not exist in web.xml.

Topics

#web.xml#error handling#servlet configuration#deployment descriptor

Community Discussion

No community discussion yet for this question.

Full 1Z0-900 Practice