Grails: URL mapping with .gsp extension/format

135 Views Asked by At

I have a url request like www.xyz.com/customer/list.gsp

When I try to map the url to remove .gsp:

"/customer/list.gsp"(controller: "customer") {
        action = "list"
    }

grails application won't recognize the url and is throwing 404 error. Am I missing something here?

2

There are 2 best solutions below

1
Daniel On

Update: apparently it is fine to map to GSPs. I still think that the info below may be helpful so I'm leaving the answer up, but perhaps I have misunderstood your question.

Original response:

You shouldn't be mapping to or requesting gsps at all. They're used to generate views, but are not viewable without rendering.

Instead, go to url like www.xyz.com/customer/list and map that like

"/customer/list" (controller: "customer") {
    action = "list"
}

Or even better, you don't need a custom mapping for each endpoint. A default like this will work:

"/$controller/$action?/$id?" { }

Your CustomerController will render the list.gsp in the list action.

0
Jeff Scott Brown On

If you want to remove .gsp from the url then you can use a mapping like this...

"/customer/list"(controller: "customer") {
        action = "list"
}

You could also do this...

"/customer/list"(controller: "customer", action: "list")

If you want 1 mapping for all the actions in the controller, you could do this:

"/customer/$action"(controller: "customer")

The default generated mapping includes "/$controller/$action" which allows you map to any action in any controller.

With any of that, sending a request to /customer/list would work.