简体   繁体   中英

How to remove charset from Content-type when using HttpServletResponse in Struts

I'm trying to send a response with "application/json" content-type. The server only accepts this content-type.

But when I try to set the content-type, it automatically adds "charset=ISO-8859-1" and this is causing problems. Is there a way to remove it?

I've added the code of how I'm setting the content-type and getting the writer in HttpServletResponse.

response.setContentType("application/json");
response.getWriter().println(json);

I need the content-type to be just "application/json".

try this:

response.setContentType(MediaType.APPLICATION_JSON_VALUE);
ServletOutputStream outputStream = response.getOutputStream();
outputStream.write(res.getBytes(StandardCharsets.UTF_8));
outputStream.flush();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM