Spring MVC redirect 参数丢失
如题,当中文时参数会丢失
代码
public String redirecturl( RedirectAttributes redirectAttributes) throws Exception {
String error= java.net.URLEncoder.encode(
"错误提示信息",
"utf-8");
redirectAttributes.addFlashAttribute(
"error",
error);
return
"redirect:/url";
}
@RequestMapping(value =
"url")
public String url(Model model,@ModelAttribute(
"error")
String error) throws Exception {
String error=java.net.URLDecoder.decode(
error,
"utf-8");
model.addAttribute(
"error",
error);
return
"jspview";
}
使用上述方式即可解决中文丢失问题。原因是默认redirect使用的是iso-8859-1编码,会出现乱码和丢失情况。