The filter method in ssm solves the problem of garbled post

Post garbled problem description :
input data on the front-end page, and the last stored data appears garbled.

Solution : add filter configuration in web.xml

<!--解决post 乱码问题的过滤器-->
    <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>
    </filter>
    <filter-mapping>
        <filter-name>characterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

Need to pay attention to the placement of the filter code snippet
Insert picture description here

If the placement position is wrong, it will prompt the placement order of the labels, and place the filters according to the prompt order information.
The label sequence is as follows:
(icon?,display-name?,description?,distributable?,context-param*,filter*,filter-mapping*,listener*,servlet*,servlet-mapping*,session-config?,mime- mapping*,welcome-file-list?,error-page*,taglib*,resource-env-ref*,resource-ref*,security-constraint*,login-config?,security-role*,env-entry*, ejb-ref*,ejb-local-ref*)"

Guess you like

Origin blog.csdn.net/Hambur_/article/details/110819758