例外是: 无法在此处发出重定向(..)。之前对重定向(..)的调用已经重定向了响应.. 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
答案 0 :(得分:0)
如果URL包含特殊字符,则需要对其进行编码,这些特殊字符在编程语言中具有特殊含义,如groovy。
按如下方式编码网址
import java.net.URLEncoder;
String url = "http://localhost:8080/auth/index?param1=<";
String encodedUrl = URLEncoder.encode(url, "UTF-8");
println encodedUrl
redirect(url: encodedUrl)
答案 1 :(得分:0)
如果使用重定向,则使用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
}