使用response的writer方法中中文乱码问题解决

response运行过程:
使用response的writer方法中中文乱码问题解决_第1张图片

使用response的writer方法中中文乱码问题解决_第2张图片

这是一个servlet文件

package content;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TextServlet extends HttpServlet {

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		**//设置response查询的码表
		response.setCharacterEncoding("UTF-8");
		//通过一个头"Content-type"告知客户端使用何种码表
		response.setHeader("Content-type", "text/html;charset=UTF-8");
		
		PrintWriter writer = response.getWriter();
		writer.write("中国!");**
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}
} 

你可能感兴趣的:(工作运用)