• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mock exam question

 
Ranjani Theyagarajan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In one of the following i found the following question,

"Consider the following servlet class
public class MyServlet extends HttpServlet
{
public void doPost (HttpServletRequest req, HttpServletResponse res)
{
PrintWriter out = res.getWriter ();
out.println("<html><body>");
out.println("Servicing Post Method");
out.println("</body></html>");
}
}

User requests the servlet by clicking on the hyperlink of a HTML page given bellow.

<html>
<body>
<a href="/servlet/MyServlet">Get Service</a>
</body>
</html> "

And the anwer the default implementation of Generic Servlet doGet will get called.. I was puzzled and tried the same... see my code below,

HTML
=======
<a href="click">Hey</a>

Servlet
=========

public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
PrintWriter out=response.getWriter();
out.println("Hello...")'
}

I got an exception "HTTP method GET is not supported by this URL"

It would be helpful for me if anyone of you tell me whether am somewhere wrong or the mock exam answer is wrong?
 
Purushoth Thambu
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't have doGet method then requesting the page directly using URI or through anchor links will not work. I believe the question is wrong.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic