2
我有一个文件附件插件(AJAX File Upload plugin from Valums),它要求返回json类型为“text/html”。我正在开发的Web应用程序利用Spring框架,它强制返回类型为“application/json”。我想让json以“text/html”的形式返回。由于返回json的类型是“application/json”,我得到一个文件下载对话框,这是用户不应该看到的东西(该文件应该自动上传)。如何强制spring返回“text/html”而不是“application/json”?
@RequestMapping(value="attachmentUpload", method=RequestMethod.POST)
public @ResponseBody Map<String, String> attachmentUpload(
@ModelAttribute("fileUploadFB") @Valid final FileUploadFormBean fileUploadFB,
BindingResult result,
SessionStatus sessionStatus,
HttpServletResponse response) {
final Map<String, String> resultMap = new HashMap<String, String>();
resultMap.put("success", "true");
// vain attempts to force text/html; do not work
response.setContentType("text/html;charset=UTF-8");
response.setHeader("Content-Type", "text/html");
return resultMap;
}
如果有人有任何建议,将不胜感激!
传入'Accept'标头的内容是什么? – 2012-07-16 20:28:31
我认为这是“文本/ HTML”...除非我失去了一些东西。这是我在控制器或插件中设置的东西吗? – user1529955 2012-07-16 20:32:31
传入的请求将指定此项。 – 2012-07-16 20:37:02