<tfoot id='TEab4'></tfoot>
    1. <small id='TEab4'></small><noframes id='TEab4'>

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

        Servlet:提交响应后无法转发

        时间:2023-09-30
        • <tfoot id='EOQD0'></tfoot>

            <legend id='EOQD0'><style id='EOQD0'><dir id='EOQD0'><q id='EOQD0'></q></dir></style></legend>
            1. <small id='EOQD0'></small><noframes id='EOQD0'>

                <tbody id='EOQD0'></tbody>

                <i id='EOQD0'><tr id='EOQD0'><dt id='EOQD0'><q id='EOQD0'><span id='EOQD0'><b id='EOQD0'><form id='EOQD0'><ins id='EOQD0'></ins><ul id='EOQD0'></ul><sub id='EOQD0'></sub></form><legend id='EOQD0'></legend><bdo id='EOQD0'><pre id='EOQD0'><center id='EOQD0'></center></pre></bdo></b><th id='EOQD0'></th></span></q></dt></tr></i><div id='EOQD0'><tfoot id='EOQD0'></tfoot><dl id='EOQD0'><fieldset id='EOQD0'></fieldset></dl></div>
                  <bdo id='EOQD0'></bdo><ul id='EOQD0'></ul>
                • 本文介绍了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:提交响应后无法转发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:java io ioexception 无法解析来自服务器地理编码器的 下一篇:从其他方法访问变量

                  相关文章

                  最新文章

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

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

                      <legend id='Q9inU'><style id='Q9inU'><dir id='Q9inU'><q id='Q9inU'></q></dir></style></legend>
                        <bdo id='Q9inU'></bdo><ul id='Q9inU'></ul>