0

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?

Daniel
  • 3,312
  • 1
  • 14
  • 31
vinay
  • 21
  • 4

2 Answers2

0

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.

Daniel
  • 3,312
  • 1
  • 14
  • 31
  • "You shouldn't be mapping to or requesting gsps at all." - I don't agree with that. We specifically support mapping urls to GSPs (the default `UrlMappings.groovy` file does that). However, that isn't what the person in the question is doing. They are including `.gsp` in the url, but are mapping to a controller action. They are not mapping to a GSP. – Jeff Scott Brown Apr 23 '20 at 19:58
0

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.

Jeff Scott Brown
  • 26,804
  • 2
  • 30
  • 47