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