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
}
Burt Beckwith
  • 75,342
  • 5
  • 143
  • 156
Gerardo Tarragona
  • 1,185
  • 4
  • 15
  • 28
  • you should be able to run something like `grails generate-views ..` to generate the views. – krock May 25 '15 at 01:06

4 Answers4

11

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

zoran119
  • 10,657
  • 12
  • 46
  • 88
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.

Shashank Agrawal
  • 25,161
  • 11
  • 89
  • 121
Robert
  • 2,441
  • 21
  • 12
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.

Abdelsalam Shahlol
  • 1,621
  • 1
  • 20
  • 31
0

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

TOUDIdel
  • 1,322
  • 14
  • 22