<legend id='rdcY0'><style id='rdcY0'><dir id='rdcY0'><q id='rdcY0'></q></dir></style></legend>
        <tfoot id='rdcY0'></tfoot>
        <i id='rdcY0'><tr id='rdcY0'><dt id='rdcY0'><q id='rdcY0'><span id='rdcY0'><b id='rdcY0'><form id='rdcY0'><ins id='rdcY0'></ins><ul id='rdcY0'></ul><sub id='rdcY0'></sub></form><legend id='rdcY0'></legend><bdo id='rdcY0'><pre id='rdcY0'><center id='rdcY0'></center></pre></bdo></b><th id='rdcY0'></th></span></q></dt></tr></i><div id='rdcY0'><tfoot id='rdcY0'></tfoot><dl id='rdcY0'><fieldset id='rdcY0'></fieldset></dl></div>

        <small id='rdcY0'></small><noframes id='rdcY0'>

          <bdo id='rdcY0'></bdo><ul id='rdcY0'></ul>

      1. 在 jsp 文件中将 Content-Type 设置为 application/json

        Set Content-Type to application/json in jsp file(在 jsp 文件中将 Content-Type 设置为 application/json)
        <tfoot id='GSjYz'></tfoot>
          <tbody id='GSjYz'></tbody>

      2. <i id='GSjYz'><tr id='GSjYz'><dt id='GSjYz'><q id='GSjYz'><span id='GSjYz'><b id='GSjYz'><form id='GSjYz'><ins id='GSjYz'></ins><ul id='GSjYz'></ul><sub id='GSjYz'></sub></form><legend id='GSjYz'></legend><bdo id='GSjYz'><pre id='GSjYz'><center id='GSjYz'></center></pre></bdo></b><th id='GSjYz'></th></span></q></dt></tr></i><div id='GSjYz'><tfoot id='GSjYz'></tfoot><dl id='GSjYz'><fieldset id='GSjYz'></fieldset></dl></div>
          <bdo id='GSjYz'></bdo><ul id='GSjYz'></ul>

                  <legend id='GSjYz'><style id='GSjYz'><dir id='GSjYz'><q id='GSjYz'></q></dir></style></legend>

                  <small id='GSjYz'></small><noframes id='GSjYz'>

                • 本文介绍了在 jsp 文件中将 Content-Type 设置为 application/json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我创建了一些 jsp 文件,它作为响应返回一些 json 字符串.但是我看到 Content-Type 自动设置为 txt

                  I am created some jsp file that returns as a response some json string. But I see that the Content-Type is set to txt automatically

                  我的jsp代码看起来像

                  My jsp code looks like

                  <%@ page import="java.util.Random" %>
                  <%@ page language="java" %>
                  <%@ page session="false" %>
                  
                  <%
                    String retVal = "// some json string";
                  
                       int millis = new Random().nextInt(1000);
                       //    System.out.println("sleeping for " + millis + " millis");
                       Thread.sleep(millis);
                  %>
                  <%=retVal%>
                  

                  我怎样才能执行类似的操作

                  How can I perform something like

                  setHeader("Content-Type", "application/json");
                  

                  在这个例子中?

                  推荐答案

                  你可以通过页面指令.

                  例如:

                  <%@ page language="java" contentType="application/json; charset=UTF-8"
                      pageEncoding="UTF-8"%>
                  

                  • contentType="mimeType [ ;charset=characterSet ]" |"text/html;charset=ISO-8859-1"
                  • JSP 文件使用的 MIME 类型和字符编码它发送给客户端的响应.您可以使用任何 MIME 类型或对 JSP 容器有效的字符集.默认 MIME类型为 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-1.

                    这篇关于在 jsp 文件中将 Content-Type 设置为 application/json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                    本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Compiling C++ for the JVM(为 JVM 编译 C++)
                  Compile to java bytecode (without using Java)(编译成java字节码(不使用Java))
                  How to drive C#, C++ or Java compiler to compute 1+2+3+...+1000 at compile time?(如何在编译时驱动 C#、C++ 或 Java 编译器计算 1+2+3+...+1000?)
                  Java ClassLoader: load same class twice(Java ClassLoader:两次加载相同的类)
                  How to debug .class files in ECLIPSE?(如何在 ECLIPSE 中调试 .class 文件?)
                  Java quot;The blank final field may not have been initializedquot; Anonymous Interface vs Lambda Expression(Java“可能尚未初始化空白的最终字段匿名接口与 Lambda 表达式)

                    • <bdo id='TXGGi'></bdo><ul id='TXGGi'></ul>
                        <tbody id='TXGGi'></tbody>

                      <tfoot id='TXGGi'></tfoot>
                        1. <i id='TXGGi'><tr id='TXGGi'><dt id='TXGGi'><q id='TXGGi'><span id='TXGGi'><b id='TXGGi'><form id='TXGGi'><ins id='TXGGi'></ins><ul id='TXGGi'></ul><sub id='TXGGi'></sub></form><legend id='TXGGi'></legend><bdo id='TXGGi'><pre id='TXGGi'><center id='TXGGi'></center></pre></bdo></b><th id='TXGGi'></th></span></q></dt></tr></i><div id='TXGGi'><tfoot id='TXGGi'></tfoot><dl id='TXGGi'><fieldset id='TXGGi'></fieldset></dl></div>
                          <legend id='TXGGi'><style id='TXGGi'><dir id='TXGGi'><q id='TXGGi'></q></dir></style></legend>

                          <small id='TXGGi'></small><noframes id='TXGGi'>