////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
////

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.

TIP: Although GSP can render any format, not just HTML, it is more designed around rendering markup. If you are looking for a way to simplify JSON responses take a look at link:theWebLayer.html#gson[JSON Views].

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`:

[source,groovy,subs="attributes"]
.build.gradle
----
dependencies {
    //...
    implementation "org.apache.grails:grails-gsp"
}
----

In addition, for production compilation you should apply the `grails-gsp` Gradle plugin:

[source,groovy]
.build.gradle
----
apply plugin: "org.apache.grails.gradle.grails-gsp"
----

GSPs live in the `grails-app/views` directory and are typically rendered automatically (by convention) or with the link:{controllersRef}render.html[render] method such as:

[source,groovy]
----
render(view: "index")
----

A GSP is typically a mix of mark-up and GSP tags which aid in view rendering.

NOTE: 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:

[source,groovy]
----
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`:

[source,groovy]
----
${book.title}
----

WARNING: Embedding data received from user input has the risk of making your application vulnerable to an Cross Site Scripting (XSS) attack. Please read the documentation on link:security.html#xssPrevention[XSS prevention] for information on how to prevent XSS attacks.
