SpringMVC 处理post请求

1. 前端页面

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>学生信息管理系统</title>
		<style>
			body{
     
				font-size: 15px;
			}
			input[type="text"]{
     
				width: 230px;
				height: 30px;
				margin: 5px 8px;
			}
			input[type="submit"]{
     
				background-color: lightblue;
				width: 70px;
				height: 40px;
				color: white;
				border: 0px;
				font-size: 20px;
			}
			input[type="button"]{
     
				background-color: lightcoral;
				width: 70px;
				height: 40px;
				color: white;
				border: 0px;
				font-size: 20px;
			}
		</style>
	</head>
	<body>
		<h1>学生信息管理系统MIS</h1>
		<form method="post" action="http://localhost:8080/stu/add">
			<div>
				<span>姓名:</span>
				<input type="text" placeholder="请输入姓名" name="name"/>
				<br />
				<span>年龄:</span>
				<input type="text" placeholder="请输入年龄" name="age"/>
				<div>
					<span>性别:</span>
					<input type="radio" name="gender" id="" value="1" /><input type="radio" name="
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以尝试以下几种方法来解决Spring MVC发送POST请求后出现中文乱码的问题: 1. 在Spring MVC的配置文件(比如`web.xml`)中添加字符编码过滤器。例如,使用`org.springframework.web.filter.CharacterEncodingFilter`,将请求和响应的字符编码都设置为UTF-8。 ```xml <filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> ``` 2. 在Spring MVC的配置文件中,设置`RequestMappingHandlerAdapter`的`messageConverters`属性,指定使用UTF-8字符集编码。 ```xml <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"> <property name="messageConverters"> <list> <bean class="org.springframework.http.converter.StringHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <bean class="org.springframework.http.MediaType"> <constructor-arg index="0" value="text/plain;charset=UTF-8"/> </bean> </list> </property> </bean> </list> </property> </bean> ``` 3. 如果使用了`@RestController`注解来标记控制器类,可以在该类上添加`produces = "application/json;charset=UTF-8"`属性,指定响应的字符编码为UTF-8。 ```java @RestController @RequestMapping(value = "/example", produces = "application/json;charset=UTF-8") public class ExampleController { // ... } ``` 通过以上方法之一,你应该能够解决Spring MVC发送POST请求后出现中文乱码的问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值