servlet 里面用PrintWriter创建的html 怎么设置编码?

public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException{
PrintWriter out = response.getWriter();
response.setCharacterEncoding("UTF-8");
request.setCharacterEncoding("UTF-8");
String base = request.getContextPath();
out.print("");
out.print("

");
out.print("");
out.print("DemoOne");
out.print("");
out.print("");
out.print("欢迎登陆这个界面");
out.print("");
out.print("");
out.print("");
out.print("");
out.print("");
out.print("");
out.print("");
out.print("");
out.print("");
out.print("选择天气");
out.print("");
out.print("");
}

这样子出来的编码都是??怎么显示中文?

1个回答

rotected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
System.out.println("处理post请求");
/* PrintWriter out=resp.getWriter();
resp.setContentType("text/html;charset=utf-8");
out.println("post 请求处理完成!");*/

resp.setContentType("text/html;charset=utf-8");
ServletOutputStream out_stream=resp.getOutputStream();
out_stream.println(" post 请求处理完成!");
}

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问