Getting Started

To get started with GServlet, you may want to begin by creating your first project. This section shows you how to get up and running quickly. It is highly recommended to consume the API through a dependency management tool and the artifact can be found in Maven’s central repository. it is named gservlet-api and you just need to name a dependency on it in your project. We version the project by following the Semantic Versioning, which is a general template that everyone uses and understands. The current release is 1.0.1. You can search for previous releases on Maven Central.


Release Release Date Changelog
1.0.1 21 February 2021 Changelog
1.0.0 2 January 2021 Changelog

Release Plan

  • 1.x.x : Java EE 7+ and Jakarta EE 8 support
  • 2.x.x : Jakarta EE 9 support
  • 3.x.x : Jakarta EE 10 support

If you have a prior experience with the Servlet API, creating your first web application with GServlet will feel like a breeze.





repositories {

dependencies {

Running Your First Groovy Servlet

Once your Java web server is installed and configured, you can put it to work. Five steps take you from writing your first Groovy servlet to running it. Using Maven, these steps are as follows:

  1. Create a Maven webapp project
  2. Create the groovy folder inside your webapp directory
  3. Write the servlet source code
  4. Run your Java web server
  5. Call your servlet from a web browser

Below are some examples that you can try out and for a hot reloading of your source code, set the GSERVLET_RELOAD environment variable to true in your IDE.


import org.gservlet.annotation.Servlet

class ProjectServlet {

   def projects = []

   void init() {
      projects << [id : 1, name : "Groovy", url : ""]
      projects << [id : 2, name : "Spring", url : ""]
      projects << [id : 3, name : "Maven",  url : ""]

   void get() {

   void post() {
      def project = request.body
      projects << project

   void put() {
      def project = request.body
      int index = projects.findIndexOf { == }
      projects[index] = project

   void delete() {
      def project = request.body
      int index = projects.findIndexOf { == }



import org.gservlet.annotation.Filter

class CorsFilter {

   void filter() {
      response.addHeader("Access-Control-Allow-Origin", "*")
      response.addHeader("Access-Control-Allow-Methods","GET, OPTIONS, HEAD, PUT, POST, DELETE")
      if (request.method == "OPTIONS") {
        response.status = response.SC_ACCEPTED



import org.gservlet.annotation.RequestListener

class ServletRequestListener {

   void requestInitialized() {
     println "request initialized"

   void requestDestroyed() {
     println "request destroyed"


For a deep insight, please read the Developer Guide in our documentation page.