[英]How to remove charset from Content-type when using HttpServletResponse in Struts
I'm trying to send a response with "application/json" content-type.我正在尝试使用“application/json”内容类型发送响应。 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.但是当我尝试设置内容类型时,它会自动添加“charset=ISO-8859-1”,这会导致问题。 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.我已经添加了如何设置内容类型并在 HttpServletResponse 中获取作者的代码。
response.setContentType("application/json");
response.getWriter().println(json);
I need the content-type to be just "application/json".我需要内容类型只是“应用程序/json”。
try this:尝试这个:
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
ServletOutputStream outputStream = response.getOutputStream();
outputStream.write(res.getBytes(StandardCharsets.UTF_8));
outputStream.flush();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.