public class PostServlet extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>\n <body>\n");
out.println(" <h2>\n Hello World\n </h2>\n");
out.println(" </body>\n</html>\n");
out.flush();
out.print("Hey");
out.close();
}
}
1) The code fails to compile.
2) The server will not find the
Servlet due to an incorrect URL.
3) An error page is returned from the Server.
4) The browser displays "Hello World"
What is the result of compiling the above Servlet and accessing it by typing:
"http://www.javaranch.com/test/HelloServlet"
into the address field of a browser
Q-1 Why is ans 3) correct.
Is it because :The Servlet does not implement a doGet method so, an error is returned.
but HttpServlet provides the default doGet(). Why that is not called ?
Q-2 If i change the above doPost() to doGet(), why it's printing Hey
When i say flush() the response is committed.. Now i can't do anything but it's still printing Hey ?