zoukankan      html  css  js  c++  java
  • 解决客户端向服务器写中文时乱码问题

    package com.hdh.content;

    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 TextServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //设置response的查询码表 //response.setCharacterEncoding("Utf-8"); //告知客户端我的编码 并使用相同的编码进行解码 //response.setHeader("Content-Type","text/html;charset=UTF-8");

    //设置相应内容的类型为"UTF-8" response.setContentType("text/html;charset=UTF-8"); PrintWriter writer = response.getWriter(); writer.write("中国"); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } }

    通过设置response的查询码表,并且告知客户端我的编码(utf-8)并使用相同的编码进行解码来解决向服务器写入中文时乱码现象

    
    
  • 相关阅读:
    CNN5 调用 C实现pool2d im2col col2im
    CUDA学习3 Max pooling (python c++ cuda)
    CUDA学习2 基础知识和Julia示例
    CUDA学习1 在Visual Studio和CodeBlocks上配置
    线性搜索
    CNN4 参数优化
    CNN3 im2col
    CNN2 多层卷积
    爬虫:Scrapy8
    爬虫:Scrapy7
  • 原文地址:https://www.cnblogs.com/asndxj/p/9808412.html
Copyright © 2011-2022 走看看