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

騰訊雲伺服器發消息亂碼

發布時間: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")

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

閱讀全文

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

熱點內容
新手伺服器裝什麼系統好 瀏覽:128
androidxmlui 瀏覽:713
星辰之戀在哪個app播 瀏覽:465
手機卡伺服器出錯誤是怎麼回事 瀏覽:536
cg編譯器怎麼設置 瀏覽:418
單片機教學視頻哪個好 瀏覽:598
編譯器錯誤了怎麼辦 瀏覽:77
看摩托車用什麼app好 瀏覽:405
pdf轉換excel在線轉換 瀏覽:361
php多客服 瀏覽:746
語言編譯程序如何分類 瀏覽:377
pdf下載哪個 瀏覽:77
北京防遺失加密狗地址 瀏覽:534
華為雲伺服器搭建網站 瀏覽:152
游樂場買票用哪個app最便宜 瀏覽:537
華為手機如何加密儲存 瀏覽:212
我的世界伺服器信息怎麼加點券 瀏覽:239
阿里雲盤與雲伺服器 瀏覽:71
蘋果電腦的c編程 瀏覽:319
python爬蟲淘寶店鋪跟蹤 瀏覽:730