SpringBoot中表单提交报错“Content type ‘applicationx-www-form-urlencoded;charset=UTF-8‘ not supported“

本文主要介绍了在SpringBoot应用中遇到的两个表单提交错误。第一个错误是由于前端使用表单提交,后端使用@RequestBody导致的。解决方案包括修改后端代码或前端发送JSON对象的字符串。第二个错误是因为Ajax请求contentType未设置为'application/json',导致'Unsupported Media Type'异常,解决办法是在Ajax设置contentType为'application/json'。
摘要由CSDN通过智能技术生成

异常1

2021-06-24 12:32:20.137  WARN 20024 --- [io-8080-exec-10] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported]

错误代码1

login.html,采用了Thymeleaf

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
</head>
<body>
<form action="/login" th:action="@{/login}" method="post">
    用户名:<input type="text" name="username"><br/>
    密码:<input type="password" name="password&
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值