HTTP Status 405

来源:互联网 发布:python 数组类型转换 编辑:程序博客网 时间:2024/06/08 13:18

翻译自HTTP method GET is not supported by this URL

原文

This is the default response of the default implementation of HttpServlet#doGet(). This means that the doGet() method is not properly being @Overriden, or it is explicitly being called.

You did properly @Override the doGet() method, but you’re still explicitly calling the default implementation for unclear reason.

super.doGet(req, resp);

Get rid of this line and this problem shall disappear.

The HttpServlet basically follows the template method pattern where all non-overridden HTTP methods returns this HTTP 405 error “Method not supported”. When you override such a method, you should not call super method, because you would otherwise still get the HTTP 405 error. The same story goes on for your doPost() method.

翻译

这个错误是HttpServlet#doGet()默认实现方法的默认响应。也就是说你没有正确的重写doGet()方法或者显式地调用了默认的实现方式
你正确地重写了doGet()方法,但是你显式地调用了默认的实现方式

super.doGet(req, resp);

删掉这行代码应该就没有这个问题了。

HttpServlet基本上遵循模板方法模式(template method pattern)的原理,所有没有重写HTTP的方法都将返回HTTP405错误“方法不被支持”。如果你重写这样的一个方法,不能去调用super.xxx,否则就会得到HTTP 405错误。同理,如果在doPost()中调用super.xxx,也会得到405错误。

原创粉丝点击