Servlet中文乱码处理

 1 package com.zhiyuan.servlet;
 2 
 3 import java.io.IOException;
 4 import java.io.PrintWriter;
 5 import javax.servlet.ServletException;
 6 import javax.servlet.http.HttpServlet;
 7 import javax.servlet.http.HttpServletRequest;
 8 import javax.servlet.http.HttpServletResponse;
 9 
 /**
  * <p>Title: 响应SERVLET
  * <p>Company: 
  * @description RespServlet
  * @author LIANG ZHIYUAN
  * @date 2016年5月4日下午9:41:00
  * @version 1.0
  */
 public class RespServlet extends HttpServlet {
 
     /**
      * 串行号
      */
     private static final long serialVersionUID = 4176783017819187776L;
 
     /**
      * Constructor of the object.
      */
     public RespServlet() {
         super();
     }
 
     /**
      * Destruction of the servlet. <br>
      */
     public void destroy() {
         super.destroy();
     }
     
     public void doGet(HttpServletRequest request, HttpServletResponse response)
             throws ServletException, IOException {
         this.doPost(request, response);
     }
 
     public void doPost(HttpServletRequest request, HttpServletResponse response)
             throws ServletException, IOException {
         request.setCharacterEncoding("utf-8");
         response.setCharacterEncoding("utf-8");
         response.setContentType("text/html;charset=utf-8");
         String content=request.getParameter("data");
         String str = new String(content.getBytes("ISO-8859-1"),"utf-8");
         PrintWriter writer=response.getWriter();
         writer.print(str);
         System.out.println(str);
     }
     
     /**
      * Initialization of the servlet. <br>
      *
      * @throws ServletException if an error occurs
      */
     public void init() throws ServletException {
         
     }
 
 }
上一篇:Collection集合重难点梳理,增强for注意事项和三种遍历的应用场景,栈和队列特点,数组和链表特点,ArrayList源码解析, LinkedList-源码解析


下一篇:class 文件反编译器的 java 实现