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

    1. <tfoot id='NipES'></tfoot>

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

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

        Servlet:提交响应后无法转发

        Servlet: Cannot forward after response has been committed(Servlet:提交响应后无法转发)

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

          <tfoot id='sqzT9'></tfoot>
            <bdo id='sqzT9'></bdo><ul id='sqzT9'></ul>
            <legend id='sqzT9'><style id='sqzT9'><dir id='sqzT9'><q id='sqzT9'></q></dir></style></legend>
              <tbody id='sqzT9'></tbody>

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

                  本文介绍了Servlet:提交响应后无法转发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在开发基于 geo-location 呈现内容的 servlet 页面,我想同时使用 sendRedirectforward;例如;您从 France 浏览 example.com/aPage.jsp;首先,我希望 servlet 将您重定向到 example.com/fr/aPage.jsp,然后将您转发到 resources 页面.

                  I'm working on servlet page that renders content based on geo-location, and I want to use both sendRedirect and forward together; e.g; you browse example.com/aPage.jsp from France; first I want the servlet to redirect you to example.com/fr/aPage.jsp and then forward you to the resources page.

                  这就是我的 servlet 中的内容:

                  This is what I have in my servlet:

                  public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                    ....
                    response.sendRedirect(REDIRECT_URL_BASED_ON_GEO);
                    // after redirect forward the resources page
                    RequestDispatcher view = request.getRequestDispatcher(RESOURCES_PAGE);
                    view.forward(request, response);
                    ...
                  }
                  

                  但我明白了:

                  java.lang.IllegalStateException: Cannot forward after response has been committed
                  

                  我知道错误出现是因为我不能同时使用 sendRedirectforward 一个又一个,但我不知道如何在没有这个的情况下实现我想要的(如上所述).

                  I know the error appears because I can't use both sendRedirect and forward one after another, but I don't know how to achieve what I want (as described above) without this.

                  有什么帮助吗?

                  推荐答案

                   response.sendRedirect(REDIRECT_URL_BASED_ON_GEO);
                    // after redirect forward the resources page
                  

                  在那一行之后,您的回复开始写入 clinet.

                  After that line , Your response start writing to clinet.

                  您正在尝试向其中添加其他数据.

                  And you are trying to add additional data to it.

                  服务器已经完成响应头的写入,并且正在写入内容的正文,以及您尝试在标题中写入更多内容的点 - 当然它不能倒带.

                  The server has already finished writing the response header and is writing the body of the content, and which point you are trying to write more to the header - of course it cant rewind.

                  所以,处理 servlet 时的拇指规则是

                  So,Thumb rule while dealing with servlet is

                  redirectforward添加return语句之前完成你的逻辑.所以执行到此结束.

                  Finish your logic before redirect or forward add return statement.So execution ends there .

                  这篇关于Servlet:提交响应后无法转发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  How can I detect integer overflow on 32 bits int?(如何检测 32 位 int 上的整数溢出?)
                  Local variables before return statements, does it matter?(return 语句之前的局部变量,这有关系吗?)
                  How to convert Integer to int?(如何将整数转换为整数?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在给定范围内创建一个随机打乱数字的 int 数组)
                  Inconsistent behavior on java#39;s ==(java的行为不一致==)
                  Why is Java able to store 0xff000000 as an int?(为什么 Java 能够将 0xff000000 存储为 int?)

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

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

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