I want to display simple text on a page and as such I want to return the Content-Type
as text/plain
.
Using the code below, I see plain text on the page, however the return Content-Type
is still text/html
.
How can I fix this?
NOTE: I'm using Tiles with Spring MVC. The returned "m.health" points to a tiles def that maps to a health.jsp which only contains the 1 line below.
UPDATE NOTE: I have no control over the Content-Type
or Accept
values in the HTTP Header request. I want my response to return text/plain
no matter what kind of request comes in.
Controller:
@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:
${status}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…