我已经修改了很多地方,使我的Spring MVC能够使用UTF-8工作,包括char过滤器,jsp中的contextType以及固定的MySQL,所以我的项目与UTF-8完美配合。为什么这个Spring MVC控制器返回损坏的UTF-8字符串?
然而,这个新添加的功能将不会得到正确
@RequestMapping(value = "/uploadFile", method = RequestMethod.POST, produces = "text/plain;charset=UTF-8")
public @ResponseBody
String uploadFileHandler(
@RequestParam("name") String name,
@RequestParam("type") String type,
@RequestParam("file") MultipartFile file//, HttpServletResponse response
) throws IOException {
// response.setCharacterEncoding("UTF-8");
if (file.isEmpty())
return "Empty";
正如你所看到的,我已经把procudes,和所以setCharacterEncoding。返回的字符串是在阿贾克斯用,我有
var ajax = new XMLHttpRequest();
ajax.overrideMimeType('text/xml;charset=UTF-8');
这里是形式开始在JSP
<form name = "myForm" method="POST" onsubmit="return validateForm()" enctype="multipart/form-data">
但我的网页仍显示????。那我还有什么遗漏?我没有JQuery,所以希望一个解决方案,除非必须使用它。
'返回'空''线看起来很有趣。你确定这些是ASCII字符吗?也许他们不是 - 剪切和粘贴也许? – 2014-10-06 03:58:35
tomcat或glassfish? – 2014-10-06 09:23:01
@AlvinBunk空是UTF-8而不是ascii。看看这些信件。我认为这是tomcat – Splash 2014-10-07 00:56:38