我创建了一些jsp文件,作为响应返回一些json字符串。 但我发现Content-Type自动设置为txt
我的jsp代码看起来像
String retVal =”// some json string”;
int millis = new Random().nextInt(1000);
// System.out.println(“sleeping for” + millis +” millis”);
Thread.sleep(millis);
%>
我怎样才能表现出类似的东西
setHeader(“Content-Type”,”application/json”);
在这个例子中?
你可以通过Page指令来完成。
例如:
pageEncoding=”UTF-8″%>
contentType =”mimeType [; charset = characterSet]”|
“text / html的;字符集= ISO-8859-1”
The MIME type and character encoding the JSP file uses for the
response it sends to the client. You can use any MIME type or
character set that are valid for the JSP container. The default MIME
type is text/html, and the default character set is ISO-8859