Hi, I've got a testing servlet. The strange thing is that when I implemented service(), it works just fine. But when I implemented doGet() and doPost, I would get the notorious 405 error (HTTP method POST is not supported by this URL & HTTP method GET is not supported by this URL):
public void doGet (ServletRequest req, ServletResponse res) throws ServletException, IOException {
String name = req.getParameterValues("yourname")[0];
String reply = "<HTML>\n"+
"<HEAD><TITLE>My Name Servlet Response</TITLE></HEAD>\n" +
"<BODY>\n" +
"<CENTER><BR><B>\n" +
"Hello " + name + "\n" +
"</B></CENTER>\n</BODY>\n</HTML>";
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println(reply);
out.close();
}
public void doPost (ServletRequest req, ServletResponse res) throws ServletException, IOException {
doPost(req, res);
}
For your information, I've also tried implementing doGet and doPost the other way round, that is, forwarding doGet to doPost, and I have even tried given the same implementation to these two methods separately.
The html is super simple and I've tried "get" and "post" both:
<FORM NAME="entryForm" ACTION="NameTestServlet" METHOD="post">
<INPUT TYPE="TEXT" NAME="yourname">
<INPUT TYPE="submit" VALUE=" Submit ">
</FORM>
No matter what I do, I get the error -- unless I put the implentation in the service() method. Can anyone shed some light on this? This really has wired me out. Thanks!