如何强制弹簧返回"text/html"而不是"application/json"?



我有一个文件附件插件(来自Valums的AJAX文件上传插件),它要求返回json的类型为"text/html"。我正在开发的web应用程序使用Spring Framework,它强制返回类型为"application/json"。我希望json以"text/html"的形式返回。由于返回的json类型为"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;
}

如果有人有任何建议,我们将不胜感激!

我不再返回哈希映射;返回一个字符串并将"products="text.html"添加到RequestMapping工作!

相关内容

最新更新