表单提交会存在乱码问题,中文:
Controller类
@Controller
public class HelloController {
@RequestMapping("/hello1")
public String hello(String name, Model model){
System.out.println(name);
model.addAttribute("name",name);
return "user";
}
}
web.xml和springmvc-servlet和之前的一样
index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>乱码问题</title>
</head>
<body>
<%--导包jsp的包--%>
<form action="${pageContext.request.contextPath}/hello1" method="get">
用户名: <input type="text" name="name">
<input type="submit">
</form>
</body>
</html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>乱码问题</title>
</head>
<body>
<%--导包jsp的包--%>
<form action="${pageContext.request.contextPath}/hello1" method="post">
用户名: <input type="text" name="name">
<input type="submit">
</form>
</body>
</html>
- 查看Tomcat服务器编码
- 自己写一个字符编码过滤器(“MyFilter”)
- 使用SpringMVC的字符编码过滤器(推荐)
来源:https://blog.csdn.net/qq_40871734/article/details/98759298