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