• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Mock exam question

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic