zoukankan      html  css  js  c++  java
  • URL参数中汉字转换为16进制Unicode形式

    导入JAR包: 
    import java.net.*; 
    把汉字转换为16进制Unicode形式: 
    String xw="新闻中心"; 
    String name=URLEncoder.encode(xw,"utf-8"); 
    把16进制Unicode形式字符串转换为汉字: 
    URLDecoder.decode("%E6%96%B0%E9%97%BB%E4%B8%AD%E5%BF%83","utf-8"); 

    注意:从A(UTF-8)页面中跳到B页面时:参数name带有16进制参数值时,在B页面中使用,request.getParameter()获取的参数是乱码。还不能使用URLDecoder.decode(name,"utf-8");获取"新闻中心"; 
    补充: 
    在A页面中: 
    <% 
    String xw="新闻中心"; 
    String name=URLEncoder.encode(xw,"utf-8"); 
    request.setParameter("name","name");%> 
    在B页面中: 
    <% 
    String xw=URLDecoder.decode(new String(request.getParameter("name").getBytes("iso-8859-1"),"utf-8"),"utf-8");%>这样就不会出现乱码了。

  • 相关阅读:
    vscode maven
    clojure + sumblime text SublimeREPL
    .zsh_history
    springboot-自动装配
    任务调度-Quartz
    springcloud alibaba
    canal与kafka的结合使用
    centos7安装Zookeeper
    centos7安装kafka
    vmware+centos7 设置静态ip
  • 原文地址:https://www.cnblogs.com/chenlong-50954265/p/5844559.html
Copyright © 2011-2022 走看看