import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
public class TestCharset {
public static void main(String[] args) throws UnsupportedEncodingException {
String strChineseString = "中文";
String encoding = System.getProperty("file.encoding");
System.out.println("系统默认的字符集是:" + encoding);
System.out.println(strChineseString.getBytes(Charset.forName("GBK")).length);
System.out.println(strChineseString.getBytes(Charset.forName("UTF-8")).length);
System.out.println(strChineseString.getBytes().length);
}
}
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
public class TestCharset {
public static void main(String[] args) throws UnsupportedEncodingException {
String strChineseString = "中文";
byte[] byteGBK = null;
byte[] byteUTF8 = null;
byteGBK = strChineseString.getBytes(Charset.forName("GBK"));
byteUTF8 = strChineseString.getBytes(Charset.forName("utf-8"));
System.out.println(new String(byteGBK,"GBK"));
System.out.println(new String(byteGBK,"utf-8"));
System.out.println("**************************");
System.out.println(new String(byteUTF8,"utf-8"));
System.out.println(new String(byteUTF8,"GBK"));
}
}
String strSource = "你想要转码的字符串"; String strSomeEncoding = "utf-8"; //例如utf-8 String strTarget = new String (strSource.getBytes(Charset.forName(strSomeEncoding)), strSomeEncoding);
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
public class TestSocket {
public static void main(String[] args) throws IOException {
Socket socket = new Socket();
DataOutputStream dos = null;
PrintWriter pw = null;
BufferedReader in = null;
String responseXml = "要传输的中文";
//..........
dos = new DataOutputStream(socket.getOutputStream());
pw = new PrintWriter(new OutputStreamWriter(dos)); //不带自动刷新的Writer
pw.println(responseXml);
pw.flush();
}
}
<%@ page contentType="text/html; charset=utf-8" language="java" errorPage="" %>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
var url ="http://www.baidu.com/s?industry=编码" url = encodeURI(url);
<%@ page import="java.net.URLEncoder" %>
<a href="xxxxx.xx?industry=<%=URLEncoder.encode(" rel="external nofollow" http://www.baidu.com/s?wd=编码", "UTF-8")%>">
request.setCharacterEncoding("utf-8");
String industry = new String(
request.getParameter("industry ").getBytes("ISO8859-1"),"UTF-8");
xmlHttp.open("post", url , true);
xmlHttp.setRequestHeader("Content-Type","text/xml; charset= utf-8");
xmlHttp.send(param);
/**
* @Function:writeResponse
* @Description:ajax方式返回字符串
* @param str:json
* @return:true:输出成功,false:输出失败
*/
public boolean writeResponse(String str){
boolean ret = true;
try{
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/html;charset=utf-8");
PrintWriter pw = response.getWriter();
pw.print(str);
pw.close();
}catch (Exception e) {
ret = false;
e.printStackTrace();
}
return ret;
}
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/html;charset=utf-8");
response.reset();
String header = "attachment; filename=" + picName;
header = new String(header.getBytes(), "UTF-8");
response.setHeader("Content-disposition", header);
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有