Groovy Server Pages (GSP) is a presentation language for web applications, similar to JSP. GSP allows static and dynamic content to be mixed in the same document. The result is a dynamically generated HTML, XML or other type of document in response to a Web client request.
Groovy Server Pages (GSP) is a view technology which can be used for designing web application using Grails Framework. Developing GSP are very much similar to that of designing web pages with Active Server Pages (ASP) and Java Server Pages (JSP) but coding is very much simpler and easier than both of them. Users are provided with facility of having static, dynamic as well as mix of both contents at a time in a single application.
The output can be dynamically rendered to different forms like : HTML, XML, text and any other format based on Web client request object.If you are beginner in learning groovy, please read Introduction to Groovy – Scripting Language.
Advantages of using GSP using Grails
- A GSP uses Groovy GString for evaluation of expression generally using ${….} but whereas in JSP EL expressions are used for the same purpose but they are restricted only to object navigation to overcome this disadvantage JSTL functions can to be written for creating static helper methods, registering them through a taglib descriptor, adding a taglib declaration and finally implementing them using the function.
- A developer has been provided with Logical and Iterative tags in GSP with safe navigation operator and Elvis operator which can be implemented easily to fetch the needed results according to their requirement. For example these operators can be implemented in this manner:
Safe navigation operator :
${book.pages?.no()}
- Elvis operator :
${totalpages ?: 100}
- A GSPhas ability for invoking methods through Grails dynamic tags which makes it easier to produce well-formed markup:
<!-- With a regular tag --> <a href="<g:createLink action="list" />">Click here</a> <!-- As a method call --> <a href="${createLink(action:'list')}">Click here</a>
- Creating and testing custom tag libraries using GSP are very easier then JSP since there is no need for developer to code tld files and taglib declarations.