• 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 
    10 /**
    11  * <p>Title: 响应SERVLET
    12  * <p>Company: 
    13  * @description RespServlet
    14  * @author LIANG ZHIYUAN
    15  * @date 2016年5月4日下午9:41:00
    16  * @version 1.0
    17  */
    18 public class RespServlet extends HttpServlet {
    19 
    20     /**
    21      * 串行号
    22      */
    23     private static final long serialVersionUID = 4176783017819187776L;
    24 
    25     /**
    26      * Constructor of the object.
    27      */
    28     public RespServlet() {
    29         super();
    30     }
    31 
    32     /**
    33      * Destruction of the servlet. <br>
    34      */
    35     public void destroy() {
    36         super.destroy();
    37     }
    38     
    39     public void doGet(HttpServletRequest request, HttpServletResponse response)
    40             throws ServletException, IOException {
    41         this.doPost(request, response);
    42     }
    43 
    44     public void doPost(HttpServletRequest request, HttpServletResponse response)
    45             throws ServletException, IOException {
    46         request.setCharacterEncoding("utf-8");
    47         response.setCharacterEncoding("utf-8");
    48         response.setContentType("text/html;charset=utf-8");
    49         String content=request.getParameter("data");
    50         String str = new String(content.getBytes("ISO-8859-1"),"utf-8");
    51         PrintWriter writer=response.getWriter();
    52         writer.print(str);
    53         System.out.println(str);
    54     }
    55     
    56     /**
    57      * Initialization of the servlet. <br>
    58      *
    59      * @throws ServletException if an error occurs
    60      */
    61     public void init() throws ServletException {
    62         
    63     }
    64 
    65 }
  • 相关阅读:
    MVC MVP MVVM三者的区别
    有状态组件 和 无状态组件的区别
    判断数据类型的几种方法
    bind的使用
    新时代web组件开发标准
    node.js上传文件
    封装的组件
    mysql数据库比较,各数据库不同之处
    node.js中使用Redis
    centos下安装nodejs的三种种方式
  • 原文地址:https://www.cnblogs.com/LEARN4J/p/5459918.html
Copyright © 2020-2023  润新知