• <tfoot id='7vGaB'></tfoot>
  • <i id='7vGaB'><tr id='7vGaB'><dt id='7vGaB'><q id='7vGaB'><span id='7vGaB'><b id='7vGaB'><form id='7vGaB'><ins id='7vGaB'></ins><ul id='7vGaB'></ul><sub id='7vGaB'></sub></form><legend id='7vGaB'></legend><bdo id='7vGaB'><pre id='7vGaB'><center id='7vGaB'></center></pre></bdo></b><th id='7vGaB'></th></span></q></dt></tr></i><div id='7vGaB'><tfoot id='7vGaB'></tfoot><dl id='7vGaB'><fieldset id='7vGaB'></fieldset></dl></div>
  • <small id='7vGaB'></small><noframes id='7vGaB'>

    <legend id='7vGaB'><style id='7vGaB'><dir id='7vGaB'><q id='7vGaB'></q></dir></style></legend>

        • <bdo id='7vGaB'></bdo><ul id='7vGaB'></ul>

        自定义标头未插入到 servlet 的请求中

        Custom header not inserted in request in servlet(自定义标头未插入到 servlet 的请求中)
          <i id='lCGl4'><tr id='lCGl4'><dt id='lCGl4'><q id='lCGl4'><span id='lCGl4'><b id='lCGl4'><form id='lCGl4'><ins id='lCGl4'></ins><ul id='lCGl4'></ul><sub id='lCGl4'></sub></form><legend id='lCGl4'></legend><bdo id='lCGl4'><pre id='lCGl4'><center id='lCGl4'></center></pre></bdo></b><th id='lCGl4'></th></span></q></dt></tr></i><div id='lCGl4'><tfoot id='lCGl4'></tfoot><dl id='lCGl4'><fieldset id='lCGl4'></fieldset></dl></div>
            <bdo id='lCGl4'></bdo><ul id='lCGl4'></ul>
            <legend id='lCGl4'><style id='lCGl4'><dir id='lCGl4'><q id='lCGl4'></q></dir></style></legend>

                • <tfoot id='lCGl4'></tfoot>

                • <small id='lCGl4'></small><noframes id='lCGl4'>

                    <tbody id='lCGl4'></tbody>

                  本文介绍了自定义标头未插入到 servlet 的请求中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  有一个第三方应用程序需要通过自定义 http 标头获取信息,因此我编写了一个简单的测试应用程序来创建此标头,然后重定向到列出所有标头的页面.

                  There's a thrird party app that needs to get information via custom http headers, so I wrote a simple test app that creates this headers and then redirects to a page that lists all headers.

                  生成标头的 servlet 片段是:

                  The header-generating servlet snippet is:

                  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                      response.setContentType("text/plain");
                      response.setHeader("cust-header", "cust-val");
                      response.sendRedirect("header.jsp");
                  }
                  

                  另一方面,header.jsp 中的相关代码是:

                  On the other hand, the relevant code from header.jsp is:

                  <%
                      Enumeration enumeration = request.getHeaderNames();
                      while (enumeration.hasMoreElements()) {
                      String string = (String)enumeration.nextElement();
                      out.println("<font size = 6>" +string +": " + request.getHeader(string)+ "</font><br>");
                      }
                      %>
                  

                  显示以下标题:

                  Host: localhost:9082
                  User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; es-ES; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10 (.NET CLR 3.5.30729)
                  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
                  Accept-Language: es-es,es;q=0.8,en-us;q=0.5,en;q=0.3
                  Accept-Encoding: gzip,deflate
                  Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
                  Keep-Alive: 115
                  Connection: keep-alive
                  Referer: http://localhost:9082/HdrTest/login.jsp
                  Cookie: JSESSIONID=0000tubMmZOXDyuM4X9RmaYYTg4:-1
                  

                  就好像从未插入自定义标题一样.我该如何解决?

                  As if the custom header was never inserted. How can I fix it ?

                  谢谢

                  推荐答案

                  使用 redirect 您基本上是在指示客户端(网络浏览器)触发一个全新的 HTTP 请求.一个全新的请求也意味着一个全新的回应.将其替换为 forward:

                  With a redirect you're basically instructing the client (the webbrowser) to fire a brand new HTTP request. A brand new request also means a brand new response. Replace it by a forward:

                  request.getRequestDispatcher("header.jsp").forward(request, response);
                  

                  或者如果你真的想在重定向的请求上使用它,那么创建一个映射到 /header.jspFilter 并相应地修改标头.

                  Or if you actually want to have it on the redirected request, then create a Filter which is mapped on /header.jsp and modifies the header accordingly.

                  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
                      ((HttpServletResponse) response).setHeader("foo", "bar");
                      chain.doFilter(request, response);
                  }
                  

                  另请注意,您在 header.jsp 中显示 request 标头,而不是 response 标头.由于没有可用的直接 API 来显示响应标头,因此您希望使用外部 HTTP 标头嗅探工具(例如 Firebug(Net 面板)或 提琴手.

                  Also note that you're displaying the request headers in the header.jsp instead of response headers. Since there's no direct API avaliable to display the response headers, you'd like to investigate them using an external HTTP header sniffing tool like Firebug (the Net panel) or Fiddler.

                  这篇关于自定义标头未插入到 servlet 的请求中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 表达式)
                    <tbody id='feEV3'></tbody>
                  • <small id='feEV3'></small><noframes id='feEV3'>

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

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