2.4 A Hello World Example - Reference Documentation
Authors: Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith
Version: null
2.4 A Hello World Example
To implement the typical "hello world!" example run the create-controller command:
grails create-controller helloThis will create a new controller (Refer to the section on Controllers for more information) in the grails-app/controllers directory called helloworld/HelloController.groovy.
If no package is specified with create-controller script, Grails automatically uses the application name as the package name. This default is configurable with the grails.project.groupId attribute in Config.groovy.
Controllers are capable of dealing with web requests and to fulfil the "hello world!" use case our implementation needs to look like the following:package helloworldclass HelloController { def world() { render "Hello World!" } }
grails run-appThis will start-up a server on port 8080 and you should now be able to access your application with the URL: http://localhost:8080/helloworldThe result will look something like the following screenshot:
This is the Grails intro page which is rendered by the web-app/index.gsp file. You will note it has a detected the presence of your controller and clicking on the link to our controller we can see the text "Hello World!" printed to the browser window.

