zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    win10 1607 安装密钥 GVLK
    计算机意外地重新启动或遇到错误。windows安装无法继续。若要安装windows 请单击 确定 重新启动计算机
    在Mac中使用「dd」指令烧录ISO镜像文件到U盘
    一款免费好用的正则表达式工具:Regex Match Tracer
    全国移动短信信息中心号码查询大全
    VS2008 LINK : fatal error LNK1104: cannot open file 'atls.lib'错误解决方案
    理解全概率公式与贝叶斯公式
    改善程序员生活质量的 3+10 习惯
    TCP选项之SO_RCVBUF和SO_SNDBUF
    OpenSSL开发学习总结
  • 原文地址:https://www.cnblogs.com/LEARN4J/p/5459918.html
Copyright © 2011-2022 走看看