学到Servlet后,令人头疼的问题就是乱码问题,如下代码:- package cn.itcast.jspservlet;
- 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 servletDemo2 extends HttpServlet {
-
- public void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- response.setCharacterEncoding("UTF-8");
-
-
- PrintWriter out = response.getWriter();
-
- out.write("中国");
- }
- }
复制代码 启动Tomcat 6.0,并发布后,在浏览器上输出的却是“涓浗”,这是怎么回事?我明明已经指定编码表了,怎么还乱码呢 |