dependencies {
//...
implementation "org.grails.plugins:gsp:6.2.1"
}
1 Introduction
Version: 6.2.1
1 Introduction
Groovy Servers Pages (or GSP for short) is Grails' view technology. It is designed to be familiar for users of technologies such as ASP and JSP, but to be far more flexible and intuitive.
GSP was previously part of Grails core, but since version 3.3 it is an independent Grails plugin that can be used by defining the following dependency in your build.gradle
:
In addition, for production compilation you should apply the grails-gsp
Gradle plugin:
apply plugin: "org.grails.grails-gsp"
GSPs themselves live in the grails-app/views
directory and are typically rendered automatically (by convention) or with the render method such as:
render(view: "index")
A GSP is typically a mix of mark-up and GSP tags which aid in view rendering.
Although it is possible to have Groovy logic embedded in your GSP and doing this will be covered in this document, the practice is strongly discouraged. Mixing mark-up and code is a bad thing and most GSP pages contain no code and needn’t do so. |
A GSP typically has a "model" which is a set of variables that are used for view rendering. The model is passed to the GSP view from a controller. For example consider the following controller action:
def show() {
[book: Book.get(params.id)]
}
This action will look up a Book
instance and create a model that contains a key called book
. This key can then be referenced within the GSP view using the name book
:
${book.title}
Embedding data received from user input has the risk of making your application vulnerable to a Cross Site Scripting (XSS) attack. Please read the documentation on XSS prevention for information on how to prevent XSS attacks. |