By Just looking at URL we can not say that, it will be a call to GET or POST, although for; GET parameters are appended at the end of URL, but what if we don't have any parameter. So we can not say which method is being called.
So overall we will go with the URL-pattern match and also we can not access any thing which is inside WEB-INF directly.
As nothing is given regarding web.xml here,so we can not say whether the error page is configured or not so option 2 is ruled out. I think answer will be 4th.
default implementation for doGet method in HttpServlet returns 405 code which is SC_NOT_IMPLEMENTED, this is true for doGet and doPost other methods like doHead works pretty fine and returns code 200 without overriding it.
hope this helps. Tony
posted 10 years ago
Also, if you type a url in your address browser manually it is definitely a GET request which will trigger doGet in your case.
posted 10 years ago
sunny i agree with you, but the mock exams shows correct ans 2, if i answered 4 acc. to them it will be wrong.
1: Clicking a hyperlink 2: Submitting a foem wothout any method attribute 3: Typing the URL directly in the address bar. are three point in my knowledge where doGet is being called by default. Hence in your case its calling the doGet(req,res) method of HttpServlet class which by default reyutns the error page by default,if not overrided in your servlet class.
I do see the absence of the url-pattern entry in web.xml which plays a vital role. Perhaps it might have been ignored here since the url pattern is simple if you decode/parse it.
<server>/test/HelloServlet --> indicates the /HelloServlet should have been the url-pattern for the application/context root 'test'.
Apart from that, as other ranchers mentioned the default method gets invoked is GET (thus doGet()) if no method is explicitly mentioned while hitting the servlet. As the Servlet is not implementing the doGet() method, the container is unable to find a match. Hence the error!