grails无法在此处发出重定向(..)。当url参数包含尖括号时,先前调用重定向(..)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了grails无法在此处发出重定向(..)。当url参数包含尖括号时,先前调用重定向(..)相关的知识,希望对你有一定的参考价值。

例外情况是:无法在此处发出重定向(..)。之前对重定向(..)的调用已经重定向了响应.Stacktrace如下:org.codehaus.groovy.grails.web.servlet.mvc.exceptions.CannotRedirectException:无法在此处发出重定向(..)。先前对重定向(..)的调用已经重定向了响应。

请求网址:http://localhost:8080/auth/index?param1= <

然后扔了

ceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: javax.servlet.ServletException: Servlet execution threw an exception
    at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:198)
    at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
    ... 54 more
Caused by: org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsRuntimeException: javax.servlet.ServletException: javax.servlet.ServletException: Servlet execution threw an exception
    ... 56 more
答案

如果URL包含特殊字符,则需要对URL进行编码,这些特殊字符在编程语言(如groovy)中具有特殊含义。

编码URL如下

import java.net.URLEncoder;
String url = "http://localhost:8080/auth/index?param1=<";   
String encodedUrl = URLEncoder.encode(url, "UTF-8");
println encodedUrl​ 
redirect(url: encodedUrl)
另一答案

如果使用重定向,则使用return关键字,它不是方法中的最后一个语句。

默认情况下,Grails使用最后一个语句作为return语句。如果您重定向并且它是最后一个语句,则它会自动运行。但是,如果在if语句中使用return并且return不是最后一个语句,则情况并非如此。在这些情况下,您必须显式使用return关键字。

def someAction(){
     if(someCondition == true){
          redirect action: "anotherAction"
          return                  // this prevents the execution of the code below
     }else{
        // do something else 
     } 

     redirect action: "myAction"  // this will throw an error if the condition above matched and it redirected without return keyword
}

以上是关于grails无法在此处发出重定向(..)。当url参数包含尖括号时,先前调用重定向(..)的主要内容,如果未能解决你的问题,请参考以下文章

JSP如何实现网页重定向

Grails命令对象重定向与模型具有相同的URL /页面

防止 axios/fetch 重定向

由于重定向循环,Grails Spring Security 无法显示登录页面

如何在负载均衡器后面强制 Spring Security 发出 https 重定向请求

Grails 重定向控制器从 https 切换到 http。为啥?