嗨老师,浏览器显示不了中文该怎么做?
来源:3-4 编写自定义助手类

慕尼黑0536602
2020-12-08
嗨老师,这是源码,就是浏览器如果要显示中文,该怎么整呢?谢谢!
package helloTry;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpObject;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpVersion;
import io.netty.util.CharsetUtil;
public class CustomHandler extends SimpleChannelInboundHandler<HttpObject> {
@Override
protected void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
// 我们利用环境上下文,先拿到channel
Channel channel = ctx.channel();
//我们先打印出客户端的远程地址
System.out.println(channel.remoteAddress());
//我们需要把要发的内容,深度复制到缓冲区
ByteBuf content = Unpooled.copiedBuffer("老师很帅",CharsetUtil.UTF_8);
//设置一个Http的response格式
FullHttpResponse response = new DefaultFullHttpResponse(
HttpVersion.HTTP_1_1,
HttpResponseStatus.OK,
content);
//设置传递数据的类型跟长度
response.headers().set(HttpHeaderNames.CONTENT_TYPE,"text/plain");
response.headers().set(HttpHeaderNames.CONTENT_LENGTH,content.readableBytes());
ctx.writeAndFlush(response);
}
}
写回答
1回答
-
额,没明白。浏览器修改语言?
042021-05-31
Netty+Spring Boot仿微信-全栈开发高性能后台及客户端
SpringBoot/Netty+MUI全栈开发 同时搞定后台+ Android&iOS
1498 学习 · 684 问题
相似问题
老师,求助
回答 1
老师请问下uniapp是怎么上传文件的
回答 3