码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2017-04-10 10:42:27      阅读:339      评论:0      收藏:0      [点我收藏+]

标签:报错   前端   str   require   pat   back   imp   输入   传递   

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

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

标签:报错   前端   str   require   pat   back   imp   输入   传递   

原文地址:http://www.cnblogs.com/pwang18321767860/p/6687769.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!