1. 程式人生 > >徹底解決Spring MVC中文亂碼問題

徹底解決Spring MVC中文亂碼問題

我們在web專案中可能需要傳遞一些中文的引數,這時如果不進行處理,後臺接收到的引數是亂碼導致不能獲得預期的效果。

對於這種情況,首先確保我們jsp頁面時utf-8編碼。

1、對於post請求,我們可以在web.xml配置檔案中新增過濾器:

<filter>
        <description>字元編碼過濾器</description>
        <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>

2、對於get請求,在tomcat的server.xml配置檔案中配置:

<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />

新增URIEncoding="utf-8"
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="utf-8"/>

相關推薦

徹底解決Spring MVC 中文亂碼 問題

表單提交controller獲得中文引數後亂碼解決方案,缺一不可: 1    <%@ page language="java"contentType="text/html; charset=

徹底解決Spring MVC中文亂碼問題

我們在web專案中可能需要傳遞一些中文的引數,這時如果不進行處理,後臺接收到的引數是亂碼導致不能獲得預期的效果。對於這種情況,首先確保我們jsp頁面時utf-8編碼。1、對於post請求,我們可以在web.xml配置檔案中新增過濾器:<filter>

總結徹底解決Spring MVC+Mybatis中文亂碼問題

Java對於新手最容易出現的問題就是中文亂碼的問題。今天我就來總結一下徹底解決Spring mvc+Mybatis中文亂碼的方案。 首先要看打一斷點看一下Controller接收到引數值是否正常。如果不正常多半是因為Spring或者頁面編碼的設定問題。 一、Sprin

解決spring boot中文亂碼問題

地址 今天 解決 正常 img alt mage com 沒有 在開發或學習當中,我們不可避免的會碰到中文亂碼的問題(好想哭,但還是要保持微笑!) 今天,在學習spring boot中碰到了中文亂碼問題。 首先,看了一下workspace是不是設置utf-8默認字符集:

spring mvc 中文亂碼處理

param pat encoding mvc ren 處理 web.xml framework 亂碼處理 在 web.xml中添加 <filter> <filter-name>characterEncodingFilter</filt

徹底解決Intellij IDEA中文亂碼問題

      關於JAVA IDE開發工具,Eclipse系列和Intelli IDEA是大部分公司的主要選擇,從開發者的選擇角度,Intellij IDEA似乎比Eclipse系列更受歡迎一些。當我們使用Intellij IDEA開發時,我們發現出現中文亂碼問題,造成中文亂碼的根

解決Spring MVC @ResponseBody返回中文字串亂碼問題

引起亂碼原因為spring mvc使用的預設處理字串編碼為ISO-8859-1, 具體參考org.springframework.http.converter.StringHttpMessageConverter類中public static final Charset D

解決Spring MVC @ResponseBody返回中文字符串亂碼問題

有效 per log bean dia media converter 原因 ons 引起亂碼原因為spring mvc使用的默認處理字符串編碼為ISO-8859-1 具體參考org.springframework.http.converter.StringHttpMess

解決Spring MVC @ResponseBody出現問號亂碼問題

原因是SpringMVC的@ResponseBody使用的預設處理字串編碼為ISO-8859-1,而我們前臺或者客戶端的編碼一般是UTF-8或者GBK。現將解決方法分享如下! 第一種方法: 對於需要返回字串的方法添加註解,如下: @RequestMapping(value="/getUser",

解決 Spring MVC 使用 CommonsMultipartResolver 上傳檔案亂碼

使用SpringMVC配置MultipartResolver來上傳中文檔名的檔案時,出現中文亂碼的問題,解決方案: @Bean public MultipartResolver multipartResolver(){ CommonsMultipartResolver multipa

Spring Boot 中文亂碼解決

使用SpringBoot開發,對外開發介面供呼叫,傳入引數中有中文,出現中文亂碼,查了好多資料,總結解決方法如下: 第一步,約定傳參編碼格式 不管是使用httpclient,還是okhttp,都要設定傳參的編碼,為了統一,這裡全部設定為utf-8

SpringMVC如何解決POST請求中文亂碼問題,GET的又如何處理呢?

rec ppi utf-8 proto style app 亂碼問題 ping 解決 在web.xml中 <filter> <filter-name>CharacterEncodingFilter</filter-name>

解決servlet請求中文亂碼的通用過濾器程序

狀態 odin blog 完成 ktr try nds pos ren import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.Map; impor

解決mssql localdb 中文亂碼問題

database alt use ldb mdf lba local 查詢 mssq 使用以下查詢語句即可。 alter database "E:\.Net Core\Database\hm.mdf" set single_user with rollback immedi

解決jdbc MySQL中文亂碼問題

spa style mysql安裝 亂碼問題 img images mysql ges 安裝 進MySQL安裝目錄,打開my.ini        這兩個地方改成gbk               重啟服務解決jdbc MySQL中文亂碼問題

關於netbeans解決c/c++中文亂碼的問題

開發環境的問題關於netbeans解決c/c++中文亂碼的問題

遠程連接Oracle 服務器 解決Oracle查詢中文亂碼

nbsp OS scott developer 日期 ace use dos 服務器端 Dos方法: 依托於 目錄下的文件 使用plsql developer 客戶端軟件進行連接 需要配置一下: 就是把Dos的客戶端配置進來 然後,把服務器端的文件拷貝到你

Linux/Centos解決安裝oracle11g中文亂碼的問題

Oracle Linux Centos 系統 運維 解決Linux下安裝oracle11g中文亂碼的問題新建一個目錄,上傳字體包zysong.ttf到新建的目錄,命令如下: #mkdir –p /usr/share/fonts/zh_CN/TrueType #cd /usr/share/f

解決Spring Mvc中對象綁定參數重名的問題

uid NPU public double method 修改 名稱 ble size html頁面 <form method=‘post‘ action=‘url‘> 用戶名 <input type=‘text‘ name=‘name‘>

weui不帶time的日期選擇框同時解決確定按鈕中文亂碼問題

<input class="weui_input" id="start_time" style="float: left;width:40%" type="text" readonly value="" />   $("#start_time").dateti