In Grails 6.2.3, I have to handle request with .gsp extension like http://localhost:8080/report/view.gsp?a=b
I can't map this URL to controller, action. It will always return error 404.
The default UrlMappings.groovy
below should handle this case because .$format
is optional. It should simply mapped to $controller
and $action
.
"/$controller/$action?/$id?(.$format)?"{
constraints {
// apply constraints here
}
I test URL with many other extensions and they are all work without any modification to UrlMappings.groovy
. For example
http://localhost:8080/report/view.gspx?a=b
http://localhost:8080/report/view.abc
http://localhost:8080/report/view.xyz
This question suggests it should work, but it from Grails-3.3. Grails: URL mapping with .gsp extension/format
This is happening because your *.gsp
paths are being handled by GroovyPagesServlet
. To fix it, you need to remove GroovyPagesServlet
:
package stackoverflow
class GroovyPagesServletMock {
}
resources.groovy
import stackoverflow.GroovyPagesServletMock
// Place your Spring DSL code here
beans = {
groovyPagesServlet(GroovyPagesServletMock)
}
I got it working this way. Hope this helps!