JavaWeb解決中文亂碼

一、Get請求,方案有兩種編碼

  A:修改Tomcat配置文件 server.xml   URIEncoding="UTF-8"server

     如:<Connector port="8081" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8445" URIEncoding="UTF-8" />xml

 B:將從Request做用域中取的參數按iso-8859-1編碼得byte值,再轉成utf-8編碼字符串utf-8

  如: String userName= request.getParameter("userName");作用域

            userName = new String(userName.getBytes("iso-8859-1"),"utf-8");字符串

二、POST請求get

  request.setCharacterEncoding("utf-8");io

相關文章
相關標籤/搜索