myeclipse用的是UTF-8,可是浏览器用的是GBK,我这里将他们转码了为什么还不可以,求教
客户端出现乱码 如下:
hello world!
濞嗐垼绻嬮崗澶夊閿涳拷
- package cxw.study.net.ie_server;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.PrintWriter;
- import java.net.ServerSocket;
- import java.net.Socket;
- public class MyTomcat {
- public static void main(String[] args) throws IOException {
- ServerSocket ss = new ServerSocket(9090);
- Socket s = ss.accept();
- System.out.println(s.getInetAddress().getHostAddress() + "...connection");
- InputStream in = s.getInputStream();
- byte[] buf = new byte[1024];
- int len = in.read(buf);
- String text = new String(buf, 0, len);
- System.out.println(text);
- // 给客户端一个反馈信息
- PrintWriter out = new PrintWriter(s.getOutputStream(),true);
- byte[] b = "欢迎光临!".getBytes();
- out.println("hello world!");
- out.println(new String(b,"GBK"));
- s.close();
- ss.close();
- }
- }
复制代码
|
|