Grails. Could not resolve view with name 'index' in servlet with name 'grailsDispatcherServlet'
Asked Answered
G

4

14

I'm getting started with Grails (3.x) Framework but I got stuck with this error while trying to render domain content to a view:

Error 500: Internal Server Error
URI /hello/index
Class javax.servlet.ServletException
Message: Could not resolve view with name 'index' in servlet with name 'grailsDispatcherServlet'

HelloController.groovy:

package helloworld   
class HelloController {

    def index() {
        def Person persona1 = new Person(firstName: "someone", lastName: "stuck", age: 21)
        [persona:persona1]
    }
}

Person.groovy:

package helloworld

class Person {
    String firstName
    String lastName
    int age
}
Gersham answered 25/5, 2015 at 0:8 Comment(1)
you should be able to run something like grails generate-views .. to generate the views.Gastronome
I
11

Make sure that grails-app/views/hello/index.gsp file exists.

Incredulous answered 25/5, 2015 at 0:59 Comment(1)
This is not the proper solution. Its problem related redirect of file regarding view and model.Jam
L
7

I know that this has an answer, but I thought I'd chime in that I am using Grails 3.0.11 and I found that somethings code like the following will work

render(view: 'index', model: [data: value])

Where as the following will fail with the error above.

def index() {
    [data:value]
}

If I have time, I will poke around more with this and attempt to understand what's going on.

Latif answered 29/1, 2016 at 22:48 Comment(1)
This worked for me with gson views. Does anyone know why just returning the model map doesn't work?Downtown
L
2

if you're using GNU/Linux, check the folder name, files, etc. for case inconsistency.

grails-app/views/Hello/index.gsp
grails-app/views/hello/index.gsp <-- Not the same

GNU/Linux is case sensitive.

Lunik answered 12/10, 2018 at 17:10 Comment(0)
R
0

grails generate-views - generates GSP views for the given domain class

Relate answered 6/5, 2018 at 17:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.