1. 程式人生 > >表單以post方式或者get方式提交,如何解決中文亂碼問題?

表單以post方式或者get方式提交,如何解決中文亂碼問題?

post方式:

在 接受請求 的頁面 設定  request.setCharacterEncoding("utf-8");

get方式:

治標方法:


String username=request.getParameter("username");

byte[] username1=username.getBytes("ISO-8859-1");//將字串 拆成位元組

String username=new String(username1,"utf-8"); //將位元組轉換成 字串

治本方法:


將 config中的server.xml 檔案中新增一個 URIEncoding="UTF-8"