Problems with Grails 404 UrlMapping

前端 未结 3 1862
旧时难觅i
旧时难觅i 2020-12-11 04:27

I\'m having some problems getting Grails to map my 404 errors to an errors controller like in the documentation. I\'m running Grails 1.3.5 and when I add the following mappi

相关标签:
3条回答
  • 2020-12-11 04:43

    Add the following code to your application's scripts/Events.groovy:

    import groovy.xml.StreamingMarkupBuilder
    
    //modify the generated web.xml so that it supports being mapped to 'error'
    eventWebXmlEnd = {String tmpfile ->
        //find the filter mapping to change
        String filterNm = "grailsWebRequest"
        def root = new XmlSlurper().parse(webXmlFile)
        def gwr = root."filter-mapping".find { it."filter-name" == filterNm }
        if (!gwr.size()) throw new RuntimeException(
            "[fail] No Filter named $filterNm")
    
        // xml is as expected, now modify it and write it back out
        gwr.appendNode {
            dispatcher("ERROR")
        }
        // webXmlFile is an implicit variable created before event is invoked
        webXmlFile.text = new StreamingMarkupBuilder().bind {
            mkp.declareNamespace("": "http://java.sun.com/xml/ns/j2ee")
            mkp.yield(root)
        }
    }
    

    See this post for an explanation. Note that I've copied the above script from that posting, but it had to be amended as the web.xml's structure appears to have changed since the time of the posting's writing.

    0 讨论(0)
  • 2020-12-11 04:46

    http://jira.codehaus.org/browse/GRAILS-4232 I think this is a known issue

    0 讨论(0)
  • 2020-12-11 04:48

    after deleting whitespace, the problem solved

    "404"(controller:'errors', action:'notFound')

    0 讨论(0)
提交回复
热议问题