[org.springframework.web.HttpRequestMethodNotSupportedException: Request method ‘POST‘ not supported

今天做练习项目的时候,完成注册功能的时候报了这个错误提示[org.springframework.web.HttpRequestMethodNotSupportedException: Request method ‘POST‘ not supported]

注册后并没有如想象中一样跳转到网站首页,而是报了以下错误:

There was an unexpected error (type=Method Not Allowed, status=405)的错误,方法不被允许。

网上找了很多资料,一开始以为是前后端请求方法不一致造成的,于是查看了自己代码中对应的注解,但是发现并没有问题。

@RequestMapping(value = "/reg.action",method = RequestMethod.POST)

@RequestMapping对应的方法参数也是post,而且奇怪的是表单数据居然能同步到数据库中,说明请求应该是正常的,只是页面会报错,后来偶然看到网上的一篇帖子,才恍然大悟。

<INPUT class="btn" tabIndex="4" type="submit" value="注 册" @click="reg()">

报错的原因很简单, 利用axios提交一次数据后,表单的"submit"又提交了一次,覆盖了axios的页面跳转,这也是为什么数据能正常请求页面却报错的原因。

所以只要把type属性中的submit改为button,就可以正常跳转了。之前也遇到过类似的错误,一点点小的地方就会头疼半天,现在是完全记住这个问题了

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
当你看到org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'PUT' not supported的错误消息时,它意味着你正在尝试使用PUT请求方法,但该方法在你的代码中并未被支持。 这通常是因为你的代码中没有相应的处理程序方法来处理PUT请求。在你的代码中,你使用了@PostMapping注释来映射HTTP POST请求到特定的处理程序方法。但是,你需要使用@RequestMapping注释来映射HTTP PUT请求到相应的处理程序方法,或者使用@PutMapping注释作为快捷方式来映射HTTP PUT请求。 简而言之,你需要在你的代码中添加一个处理程序方法,并使用@RequestMapping或@PutMapping注释将该方法映射到HTTP PUT请求。这样,当你使用PUT请求时,就不会再出现org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'PUT' not supported的错误了。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [org.springframework.web.HttpRequestMethodNotSupportedException: Request method ‘GET‘ not supported](https://blog.csdn.net/weixin_45157411/article/details/123665632)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method ‘GET‘ not...](https://blog.csdn.net/qq_44347175/article/details/125697957)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值