Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

doGet & doPost leading to 405 error?

843841May 13 2007 — edited May 13 2007
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!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 10 2007
Added on May 13 2007
4 comments
861 views