I am developing a Grails web application (mainly as a training exercise). Earlier, I wrote some standard Grails applications, but in this case I wanted to try to create a controller that intercepts all requests (including static html) of the form:
<a href="/testApp/testJsp.jsp">test 1</a> <a href="/testApp/testGsp.gsp">test 2</a> <a href="/testApp/testHtm.htm">test 3</a> <a href="/testApp/testHtml.html">test 4</a>
The goal is to perform simple business logic (audit) every time a user clicks on a link. I know that I can do this using a filter (or a number of other methods), however I thought this should work too, and wanted to do it using the Grails framework.
I installed the Grail UrlMappings.groovy file to map all URLs of this form (/ $ myPathParam?) To one controller:
class UrlMappings { static mappings = { "/$controller/$action?/$id?"{ constraints { } } "/$path?" (controller: 'auditRecord', action: 'showPage') "500"(view:'/error') } }
In this controller (in the corresponding "showPage" action), I printed the path information, for example:
def showPage = { println "params.path = " + params.path ... render(view: resultingView) }
The println results in showPage action for each of my four links:
testJsp.jsp testGsp.gsp testHtm.htm testHtml
Why is the last "testHtml" and not "testHtml.html"?
In the previous ( request ), Olexandr encountered this problem and was recommended to simply combine the request.format value, which really returns html ". However, request.format also returns" html "for all four links.
I am interested in understanding what Grails does and why. Is there a way to configure Grails, so the params.path variable in the controller shows "testHtml.html" rather than overriding the "html" extension? It does not seem to remove the extension for any other type of file (including .htm). Is there a good reason why this is done? I know that itβs a little unusual to use a controller for static html, but still I would like to understand what is happening.