window.location.href传参中文乱码问题

window.location.href="${pageContext.request.contextPath}/story/exportStoryInfo?domainId="+domainIds                       
                        +"&requirementName="+requirementName;

前端页面需求名称输入“4.19活动”,传递到后台时出现中文乱码问题:

解决方案:

             1.jsp页面中修改为

window.location.href="${pageContext.request.contextPath}/story/exportStoryInfo?domainId="+domainIds                       
                        +"&requirementName="+encodeURI(encodeURI(requirementName));

             2.crontroller层,引入import java.net.URLDecoder;:

String requirementName = URLDecoder.decode(request.getParameter("requirementName"), "utf-8"); 获取中文参数

 同时将代码以如下格式书写,不然会报错

          try {
                String requirementName = URLDecoder.decode(request.getParameter("requirementName"), "utf-8");
                StoryFilterVo.setRequirementName(requirementName);
                XXXXX;
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

posted on 2017-04-10 10:21  pwang  阅读(2710)  评论(0编辑  收藏  举报

导航