最近一段时间一直从事SWING界面和EJB方面的开发,今天偶尔重新温习了一下BS方面的开发,结果仅仅写了一个简单的servlet,提交之后访问servlet之后总是会报HTTP method POST is not supported by this URL错误, 感到很疑惑,之前在BS开发过程中重来也没有遇到过这类错误,百度一下之后也没有解决问题,最后发现竟然是在重写的doPost多加了一个语句super.doPost导致的,无奈之下只好下了tomcat的原代码,打开javax.servlet.http.HttpServlet.java文件之后才发现超类的doPost方法如下:
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
String protocol = req.getProtocol();
String msg = lStrings.getString("http.method_post_not_supported");
if (protocol.endsWith("1.1")) {
resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, msg);
} else {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
}
}
也就是说不管你的http是不是1.1的,都是用resp.sendError方法返回一个http.method_post_not_supported的错误信息给前台界面,把我害的好苦,强烈谴责tomcat代码的注释,应该注明不要加super.doPost,不能总让我们看你们的源代码吧.呵呵 .