【发布时间】:2014-10-06 03:51:40
【问题描述】:
我已经修改了很多地方以使我的 Spring MVC 可以使用 UTF-8,包括一个 char 过滤器、jsp 中的 contextType,以及修复 MySQL,所以我的项目可以完美地使用 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。返回的字符串在 Ajax 中使用,我有
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,所以希望没有使用它的解决方案,除非必须。
【问题讨论】:
-
return "Empty"行看起来很有趣。你确定那些是ASCII字符吗?也许他们不是——也许是剪切和粘贴? -
tomcat 还是 glassfish ?
-
@AlvinBunk Empty 是 UTF-8 而不是 ascii。看看这些字母。我
标签: java ajax spring-mvc utf-8