首先需要在前台的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;
}