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传参中文乱码问题
,