js中通超链接向后台传值,中文乱码(springmvc)
2017-10-15 19:21
525 查看
首先需要在前台的js中先经过两次的编码,再在后台中用utf-8解码
案例:
<script type="text/javascript" charset="UTF-8">
function search() {
var faultAddr = encodeURI(document.getElementById("username").value);
username= encodeURI(username); //需要通过两次编码
window.location.href = "/website/searchFile/?username="+username";
document.getElementById("form2").submit();
}
</script>
Java后台中:
@RequestMapping("/searchFile")
public ModelAndView serchFile(Pageable pageable,String username,HttpServletRequest request) throws IOException {
try{
username= URLDecoder.decode(username,"utf-8");
}catch(Exception e){
e.printStackTrace();
}
mv.setViewName("/website/download");
return mv;
}
案例:
<script type="text/javascript" charset="UTF-8">
function search() {
var faultAddr = encodeURI(document.getElementById("username").value);
username= encodeURI(username); //需要通过两次编码
window.location.href = "/website/searchFile/?username="+username";
document.getElementById("form2").submit();
}
</script>
Java后台中:
@RequestMapping("/searchFile")
public ModelAndView serchFile(Pageable pageable,String username,HttpServletRequest request) throws IOException {
try{
username= URLDecoder.decode(username,"utf-8");
}catch(Exception e){
e.printStackTrace();
}
mv.setViewName("/website/download");
return mv;
}
相关文章推荐
- js中通超链接向后台传值,中文乱码
- springMVCjsp向后台传值中文乱码 加个过滤器
- js传值后台中文乱码解决
- js传值后台中文乱码解决
- js后台post传值出现中文乱码解决方法
- Tomcat载入js文件时中文乱码,后台传值都正常
- 关于js传值给后台中文乱码问题小提示
- js前台到后台中文传值乱码问题
- js向jsp页面/后台传值中文乱码
- SpringMVC 通过ajax从controller传值给js出现中文乱码
- js通过url向后台传值中文乱码问题
- js传值到后台中文乱码解决方法
- js前台到后台中文传值乱码问题
- 利用JS彻底解决超链接传参中文乱码问题
- 解决JS传到后台的中文字符在非中文环境下出现乱码“?”问题
- js url传值中文乱码之解决之道
- jsp前台向后台传值出现中文乱码
- js取后台json数据 中文乱码
- js到anction中文乱码问题和超链接中文参数乱码问题
- Springmvc中@RequestParam传值中文乱码解决方案