zoukankan      html  css  js  c++  java
  • request 解决中文乱码问题

    package request;

    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    public class RequestDemo4 extends HttpServlet {
        
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            //表单页面数据以什么吗表发过来,就控制request以什么吗表来读
            //解决post提交的中文乱码
            request.setCharacterEncoding("UTF-8");//只对post提交有效
            System.out.println(request.getParameter("username"));
            
            
            //get方式提交的数据,解决乱码问题
            //由于request.setCharacterEncoding("UTF-8")只对post方式提交的数据有效
            //所以这里get方式提交的数据只能手动解决
            //request默认使用的是iso8859编码,我们查传过来的数据在iso8859里面对应的编码,再那对应的值去utf-8吗表里查对应的值
            String name = request.getParameter("username");
            //解决get提交的中文乱码《也适用于超链接提交过来的数据-------超链接提交的额数据是以get方式提交的》
            name = new String(name.getBytes("iso8859-1"),"UTF-8");
            System.out.println(name);
        }

        
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            doGet(request, response);
        }

    }

  • 相关阅读:
    PVE6.3去订阅
    帝国CMS灵动标签当天更新的日期显示红色其他颜色变成灰色
    灵动标签实现循环子栏目数据——实现 循环子栏目数据标签 (listsonclass)的效果
    帝国cms灵动标签实现循环子栏目数据
    帝国cms常用灵动标签
    51nod1847 奇怪的数学题
    CTS2019 氪金手游
    CTS2019 重复
    UR #5 怎样跑得更快
    AGC034 F
  • 原文地址:https://www.cnblogs.com/siashan/p/3914219.html
Copyright © 2011-2022 走看看