導航:首頁 > 配伺服器 > 騰訊雲伺服器發消息亂碼

騰訊雲伺服器發消息亂碼

發布時間:2023-01-28 22:08:57

java web項目 在linux伺服器發送http post請求 中文亂碼

在進行post方式提交的時候,寫上request.setCharacterEncoding("UTF-8");
記住要在request設置提交參數之前設置字元編碼

祝:生活愉快

㈡ 發布到Linux伺服器出現頁面傳入後台的漢字亂碼

首先我是用idea開發的,我的需求是在將java項目部署到伺服器上,去調取數據,在用?id=北京 這種傳參時,linux伺服器出現亂碼,最後試了多種方法,僅供參考
頁面pageEncoding = "utf-8" charset="utf-8"

(1)server.xml 配置埠號出配置 URIEncoding = "UTF-8" 這是針對瀏覽器的編碼
還有個參數 useBodyEncodingForURI = "true"; 暫時沒搞清是什麼
(2)web.xml 中的字元集過濾器 是針對springMVC的字元集
(3) url 中 ?拼接的參數 不會經過字元集攔截器 重定向中可以使用ModelAndView 的對象,
ModelAndView mv = new ModelAndView("redirect:/index.do");
mv.addObject("id",id);
(4)自定義攔截器
①寫一個實現了 HandlerInterceptorAdpter 的攔截器 並且手動實現 preHandle() return true;
② springMVC配置文件中配置
<mvc:interceptors>
<bean id="idInterceptor" class="app.plant.interceptor.IdInterceptor"></bean>
</mvc:interceptors>
③指定字元集
String id = request.getParameter("id");
if(id != null){
id = new String(id.getBytes("iso-8859-1"),"utf-8");
request.setAttribute("id",id);
}
return true;

㈢ 求助android客戶端傳回的漢字參數,在伺服器端出現亂碼

android,遇到從android客戶端向伺服器端發送漢字亂碼問題。採用URLConnection的GET方式,在客戶端和服
務端都需要進行轉碼,而採用POST方式則不需要轉碼。具體方法如下:

用URLConnection從android發送數據有兩種方式:

第一種方式:採用get方式傳值
(1)客戶端代碼:
URL url = new URL(mUrl);
URLConnection urlConnection = url.openConnection();
InputStream is = urlConnection.getInputStream();
ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while ((current = is.read()) != -1) {
baf.append((byte) current);
}
requestInfo = new String(baf.toByteArray(), "UTF-8").trim();
is.close();

對漢字進行處理:
URLEncoder.encode(URLEncoder.encode(channelName, "UTF-8"), "UTF-8")

(2)伺服器端接收欄位:

URLDecoder.decode(URLDecoder.decode(request.getParameter("nickname"), "UTF-8"), "UTF-8")

第二種方式:採用Post方式:
客戶端代碼:
public String sendRemoteRequest(String path,String param){
Log.i("lisheng", param.toString());
Log.i("lisheng", path);
String strRes="";
OutputStream os = null;
DataOutputStream dos = null;
InputStream is = null;
BufferedReader br = null;
try {
URL url = new URL(path);
URLConnection urlConn = url.openConnection();
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
os = urlConn.getOutputStream();
dos = new DataOutputStream(os);
dos.write(param.getBytes());
dos.flush();
dos.close();
os.close();
is = urlConn.getInputStream();
br = new BufferedReader(new InputStreamReader(is,"UTF-8"));
for (String strLine = ""; (strLine = br.readLine()) != null;)
strRes = (new StringBuilder(String.valueOf(strRes))).append(strLine).toString();
is.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return strRes;
}
參數里直接寫漢字

伺服器端代碼:

request.setCharacterEncoding("UTF-8");
request.getParameter("nickname")

即可得到參數為漢字的值,不需要轉碼。

閱讀全文

與騰訊雲伺服器發消息亂碼相關的資料

熱點內容
光影app蘋果怎麼下載不了 瀏覽:971
php會員注冊代碼 瀏覽:511
csgo如何用128tick伺服器 瀏覽:571
百度網度怎麼解壓 瀏覽:946
windowsopencv源碼 瀏覽:945
origin平滑演算法 瀏覽:875
unity程序員簡歷 瀏覽:63
單片機ifelse 瀏覽:695
如何理解php面向對象 瀏覽:96
macword轉pdf 瀏覽:848
python列表求交集 瀏覽:874
解壓包如何轉音頻 瀏覽:447
機明自動編程軟體源碼 瀏覽:326
php埠號設置 瀏覽:541
phperegreplace 瀏覽:320
androidgridview翻頁 瀏覽:537
ssh協議編程 瀏覽:635
如何開我的世界電腦伺服器地址 瀏覽:861
玄關pdf 瀏覽:609
程序員學習論壇 瀏覽:940