日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

request获取中文乱码的问题

發(fā)布時間:2024/4/13 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 request获取中文乱码的问题 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
亂碼問題解決:* POST請求亂碼 :request.setCharacterEncoding("utf-8"); * GET請求亂碼解決方案一:修改tomcat/conf/server.xml <Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="utf-8"/>* 必須有修改tomcat服務(wù)器配置文件權(quán)限解決方案二:逆向編解碼username = URLEncoder.encode(username, "ISO8859-1");username = URLDecoder.decode(username, "utf-8");解決方案三:簡寫的方式(推薦使用)username = new String(username.getBytes("ISO-8859-1"),"utf-8");* request獲取中文數(shù)據(jù)亂碼(總結(jié):)* post提交* 設(shè)置request緩沖區(qū)的編碼request.setCharacterEncoding("utf-8"); * get提交* String構(gòu)造方法username = new String(username.getBytes("ISO-8859-1"),"utf-8");

處理中文亂碼

post

? ?setCharacterEncoding? //放在getParameter前才有效

get

? ?new String(str.getBytes(“ISO-8859-1”),”utf-8”)

? ?設(shè)置tomcat Connector URIEncoding=“utf-8”

package cn.itcast.request;import java.io.IOException; import java.util.Arrays; import java.util.Map; import java.util.Set;import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;/*** 獲取請求參數(shù)* @author Administrator**/ public class RegServlet extends HttpServlet {public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {/*** request獲取中文的亂碼* post請求(經(jīng)常使用)* setCharacterEncoding(String env) 設(shè)置request的緩沖區(qū)的編碼* get請求 * username = new String(username.getBytes("ISO-8859-1"),"UTF-8");*/// 設(shè)置request緩沖區(qū)的編碼(一定要在request.getParameter("username");之前)// request.setCharacterEncoding("UTF-8");// 獲取內(nèi)容,做其他操作// 獲取姓名String username = request.getParameter("username");// 解析get方式亂碼的問題username = new String(username.getBytes("ISO-8859-1"),"UTF-8");}public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {doGet(request, response);}}

?

總結(jié)

以上是生活随笔為你收集整理的request获取中文乱码的问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。