在Server中,使用response.setContentType()
方法可以设置响应的内容类型。
语法:
response.setContentType(String contentType)
参数contentType
表示响应的内容类型,通常是一个MIME类型。
例如,如果要设置响应的内容类型为text/html
,可以使用以下代码:
response.setContentType("text/html");
如果要设置响应的内容类型为application/json
,可以使用以下代码:
response.setContentType("application/json");
注意:response.setContentType()
方法应该在发送任何响应内容之前调用,以确保正确设置响应的内容类型。
亿速云「云数据库 MySQL」免部署即开即用,比自行安装部署数据库高出1倍以上的性能,双节点冗余防止单节点故障,数据自动定期备份随时恢复。点击查看>>
推荐阅读:Server中response.setcontenttype的作用是什么