public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String name = request.getParameter("name"); byte[] bytes = name.getBytes("ISO8859-1"); name = new String(bytes,"UTF-8"); response.setContentType("text/html;charset=utf-8"); response.getWriter().print("name = "+ name); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); String name = request.getParameter("name"); response.setContentType("text/html;charset=utf-8"); response.getWriter().print("name = "+ name); }
0则评论给“解决Servlet乱码问题”