Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt in free mock exam

 
V Gala
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<error-page>
<error-code>404</error-code>
<location>/not_found.html</location>
</error-page>

The above entry in the Deployment Descriptor will do what?

1 Route any request to your web application for a page or servlet that
cannot be found to not_found.html


2 Route any ServletExceptions with the code 404 thrown from your servlet to
not_found.html


3 Route any exception thrown in a servlet to not_found.html


4 Route any 404 requests to not_found.html


Answer given is 1

does anyone know explanation for answer
 
srinivas.b
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assumed in such a way

404 error mean file not found

so obviously for "a page or servlet that cannot be found" will display not_found.html
 
Francesco Bianchi
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry, I don't really agree this is so obvious.

The resons I can give you are basically two:
  • For same very strange business rules, I could decide to force the error code of my response to be 404 even if a resource has been found
  • HTTP specs are out since a certain bunch of time...ok.. But what if in a future version the 404 code changes its meaning? I think there is a reason if it's saved somewhere as a public static final int... And that not only to attach it a label to clarify its meaning...

  • By the way.. I tried a Marcus mock 1 hour ago and did same mistake as V Gala
     
    Stevi Deter
    Ranch Hand
    Posts: 265
    Hibernate Java Spring
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Here's a page with a good summary of what the web.xml <error-code /> tag does, which should explain why (1) is the correct answer.

    The summary is, exception handling takes precedence over error codes. If an exception is thrown and not handled, it's translated into a 500/503 error.

    I suspect the rest of the formulation of the question is to make sure you understand that error 404 is the "page not found" error.
     
    Francesco Bianchi
    Ranch Hand
    Posts: 62
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you Stevi. You and B T R are right.
    I have been so stupid not to even read the word "ServletException" in answer (2). I apologize for my oversight.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic