springmvc項目提交post表單參數亂碼解決辦法

 

在web項目中常常會提交表單,偶爾會遇到表單中文參數亂碼了,html

上網查了一下,各類解決辦法都有。web

如:spring

一、在html中head部分設置app

<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />

二、在form標籤中增長:post

<form method="post" action="#" accept-charset="UTF-8">

以上兩種方式都試了一下,問題仍是不能解決。ui

接着百度,找到一種方法,url

在web.xml文件中增長以下代碼:spa

    <filter>
      <filter-name>encodingFilter</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>encodingFilter</filter-name>
      <url-pattern>/*</url-pattern>
    </filter-mapping>

問題解決。code

屬文以記之!orm

相關文章
相關標籤/搜索