Hello world servlet

Before getting into the technical details, let's create an extremely simple hello world servlet. To do it, we setup a Gradle project with the build file, build.gradle, the servlet class in the file, src/main/java/packt/java9/by/example/mastermind/servlet/HelloWorld.java, and last but not least, we have to create the file src/main/webapp/WEB-INF/web.xml. The gradle.build file will look the following:

apply plugin: 'java'  apply plugin: 'jetty'    repositories {      jcenter()  }    dependencies {      providedCompile "javax.servlet:javax.servlet-api:3.1.0"  }    jettyRun {      contextPath '/hello'  }

The Gradle build file uses two plugins, java and jetty. We have already used the java plugin in the previous chapter. The jetty plugin ...

Get Java 9 Programming By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.