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();
            }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM