Spring 乱码问题

来源:互联网 发布:开淘宝店铺主要是什么 编辑:程序博客网 时间:2024/06/05 11:39

在使用Spring MVC的时候发现在前端提交的数据在数据库中是乱码的,可以通过spring提供的编码过滤器org.springframework.web.filter.CharacterEncodingFilter解决这个问题。

在web.xml下配置这个过滤器:

<?xml version="1.0" encoding="UTF-8"?>  <web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"          xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee         http://http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">    <display-name>springweb</display-name>  <welcome-file-list>  <welcome-file>index.jsp</welcome-file>  </welcome-file-list>    <filter>          <filter-name>characterEncodingFilter</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>characterEncodingFilter</filter-name>          <url-pattern>/*</url-pattern>      </filter-mapping>     .................</web-app>

原创粉丝点击