response通过writer输出数据

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	//设置response以什么码表向浏览器写
	response.setCharacterEncoding("utf-8");
	//指定浏览器以什么码表打开
	response.setHeader("content-type", "text/html;charset=utf-8");
		
	String data = "世界";
	PrintWriter out = response.getWriter();
	out.write(data);
}


更简单的可以直接改成

response.setContentType("text/html;charset=utf-8");
String data = "世界";
PrintWriter out = response.getWriter();
out.write(data);

你可能感兴趣的:(JavaEE)