【发布时间】:2012-02-15 14:47:11
【问题描述】:
我想在页面上显示简单的文本,因此我想将Content-Type 返回为text/plain。
使用下面的代码,我在页面上看到纯文本,但返回 Content-Type 仍然是 text/html。
我该如何解决这个问题?
注意:我在 Spring MVC 中使用 Tiles。返回的“m.health”指向映射到仅包含以下 1 行的 health.jsp 的切片 def。
更新说明:我无法控制 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:
${状态}
【问题讨论】:
标签: java spring-mvc content-type apache-tiles