qq_28930185
qq_28930185
采纳率0%
2016-05-09 05:01 阅读 2.9k

request.getParameter()的乱码问题

String selProvince = request.getParameter("parProvince");
selProvince = new String(selProvince.getBytes("ISO-8859-1"),"UTF-8");
System.out.println(selProvince);
输出的是????
jsp文件是<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

11条回答 默认 最新

  • Royal_lr Royal_lr 2016-05-09 05:20

    request..setCharacterEncoding("utf-8"),,这样,你再试试

    点赞 评论 复制链接分享
  • qq_28930185 qq_28930185 2016-05-09 05:26

    没有用啊,我改了好久

    点赞 评论 复制链接分享
  • qq1562609742 魈痕 2016-05-09 05:41

    request.setCharacterEncoding("UTF-8");

    点赞 评论 复制链接分享
  • qq1562609742 魈痕 2016-05-09 05:42

    request.setCharacterEncoding("UTF-8");

    点赞 评论 复制链接分享
  • tanjunqing 谈阿大 2016-05-09 06:01

    Web.xml 查看一下是不是UTF-8

    encodingFilter
    org.springframework.web.filter.CharacterEncodingFilter

    encoding
    UTF-8


    forceEncoding
    true

        查看一下发送过来是不是原本就是乱码。
    
    点赞 评论 复制链接分享
  • qq_28930185 qq_28930185 2016-05-09 06:18

    function getCity(selProvince){
    alert(selProvince);
    var loader = new net.AjaxRequest("LiveServlet?action=getCity&parProvince="+selProvince+"&nocache="
    +new Date().getTime(),deal_getCity,onerror,"GET");
    }
    我在这里查了不是乱码,在web.xml中是

    setCharacterEncodingFilter
    org.apache.catalina.filters.SetCharacterEncodingFilter

    encoding
    UTF-8

    true

    点赞 评论 复制链接分享
  • qq_17555933 胡金水 2016-05-09 06:27

    URLDecoder.decode(selProvince,"UTF-8");你这样试试看,百分百可以的,不用谢!

    点赞 评论 复制链接分享
  • seek_knowledge_lulu seek_knowledge_lulu 2016-05-09 07:36

    前台转码,后台解码

    例如:前台jsp中:

    var groupBuyerName = document.getElementById('groupBuyerName').value;
    groupBuyerName = encodeURI(encodeURI(groupBuyerName));

    后台java类中:

    String groupBuyerName = request.getParameter("groupBuyerName")
    groupBuyerName=URLDecoder.decode(groupBuyerName,"utf-8");

    点赞 评论 复制链接分享
  • seek_knowledge_lulu seek_knowledge_lulu 2016-05-09 07:38

    前台转码,后台解码

    例如:前台jsp中:

    var groupBuyerName = document.getElementById('groupBuyerName').value;
    groupBuyerName = encodeURI(encodeURI(groupBuyerName));

    后台java类中:

    String groupBuyerName = request.getParameter("groupBuyerName")
    groupBuyerName=URLDecoder.decode(groupBuyerName,"utf-8");

    点赞 评论 复制链接分享
  • GivenKing GivenKing 2016-05-09 07:39

    1:修改tomcat 中server.xml 中的编码为 UTF-8

    2:jsp 页面默认编码为 UTF-8
    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    3:接受参数时request 对象设置编码为 UTF-8
    request.setCharacterEncoding("UTF-8");
    4:hard code
    new String(request.getParameter("parProvince").getBytes("iso-8859-1","UTF-8"));
    希望对楼主的需求有所帮助。

    
    
    
    
    
    
    点赞 评论 复制链接分享
  • l81372500 l81372500 2016-05-09 07:41

    Web.xml 查看一下是不是UTF-8

    encodingFilter
    org.springframework.web.filter.CharacterEncodingFilter

    encoding
    UTF-8

    forceEncoding
    true

    点赞 评论 复制链接分享

相关推荐