我想在頁面上顯示簡單的文本,因此我想返回Content-Type
作爲text/plain
。Spring MVC 3返回內容類型:text/plain
使用下面的代碼,我在頁面上看到純文本,但返回Content-Type
仍然text/html
。
我該如何解決這個問題?
注意:我在Spring MVC中使用了Tiles。返回的「m.health」指向映射到僅包含下面1行的health.jsp的tiles def。
UPDATE注:我有超過在HTTP報頭的請求或Content-Type
值Accept
沒有控制。我想我的迴應返回text/plain
無論進來什麼樣的要求
控制器:
@RequestMapping(value = "/m/health", method = RequestMethod.GET, headers = "Accept=*")
public String runHealthCheck(HttpServletResponse response, HttpServletRequest request, Model model) throws Exception {
model = executeCheck(request, response, TEMPLATE, false, model);
model.addAttribute("accept", "text/plain");
response.setContentType("text/plain");
response.setCharacterEncoding("UTF-8");
return "m.health";
}
JSP:
$ {狀態}
我在什麼'內容Type'在'request'設置沒有控制,併產生不匹配,如果請求類型這不是我設定的。無論請求類型是什麼,我基本上都希望返回「text/plain」。 – Ali