12.16 中文乱码 字符编码转换
POST
jsp下web和java前后端交互会产生乱码,需要用CharacterEncodingFilter解决
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| <filter> <filter-name>characterEncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <async-supported>true</async-supported> <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>characterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
|
jsp页面上写点东西
1 2 3 4 5 6 7 8 9
| <hr> <form action="${pageContext.request.contextPath}/book" method="post"> 书名<input type="text" name="bookName"><br> 作者<input type="text" name="author"><br> 价格<input type="text" name="price"><br> 库存<input type="text" name="stock"><br> 销量<input type="text" name="sales"><br> <input type="submit" value="提交图书"> </form>
|
GET
在server.xml下找到
<