package com.hdh.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");
//告知客户端我的编码 并使用相同的编码进行解码
//response.setHeader("Content-Type","text/html;charset=UTF-8");
//设置相应内容的类型为"UTF-8"
response.setContentType("text/html;charset=UTF-8");
PrintWriter writer = response.getWriter();
writer.write("中国");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
通过设置response的查询码表,并且告知客户端我的编码(utf-8)并使用相同的编码进行解码来解决向服务器写入中文时乱码现象