HTTP Status 405 - HTTP method GET is not supported by this URL

翻译自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错误。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值