springmvc 中 web.xml 配置过滤器防止中文乱码

注意将表单中action的提交方式改成自己项目的路径
tocat 8.5以上可以解决GET提交中文的乱码问题
任何版本的tocat,POST方式提交中文都会乱码,所以需要配置过滤器.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>获取请求参数</title>
</head>
<body>
<h1>GET提交</h1>
<form action="http://localhost:8080/day16-springmvc/testParam" method="GET">
	用户名: <input type="text" name="user"/>
	爱好: <input type="checkbox" name="like" value="篮球"/>篮球
		<input type="checkbox" name="like" value="足球"/>足球
		<input type="checkbox" name="like" value="排球"/>排球
	<input type="submit" value="提交"/>
</form>

<h1>POST提交</h1>
<form action="http://localhost:8080/day16-springmvc/testParam" method="POST">
	用户名: <input type="text" name="user"/>
	爱好: <input type="checkbox" name="like" value="篮球"/>篮球
		<input type="checkbox" name="like" value="足球"/>足球
		<input type="checkbox" name="like" value="排球"/>排球
	<input type="submit" value="提交"/>
</form>
</body>
</html>

<!--配置post提交请求过滤器,结果post提交的乱码问题  -->
	<filter>
		<filter-name>encodingFilter</filter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF8</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>encodingFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值