问题 响应sendRedirect()处理


    if(condition true){
    request.sendRedirect("//Some URL");}

    // Some other code

现在我的问题是当我们重定向时,其他一些代码会执行还是不执行?如果执行时,在sendRedirect之前或sendRedirect之后?


2439
2018-04-28 08:13


起源



答案:


sendRedirect 方法不会停止执行您的方法。

您应该以调用方式分支您的代码 sendRedirect 是您方法中的最后一个语句,或显式调用 return; 打电话后 sendRedirect

也可以看看 http://www.coderanch.com/t/556146/Servlets/java/response-SendRedirect-session


11
2018-04-28 08:17





在重定向之后做一些事情会非常混乱,所以它应该是流程的最后一个声明。在重定向之前提交,关闭您的内容以帮助理解您的代码。


2
2018-04-28 08:20