Java was the language of choice for some of the earliest enterprise level web applications. The Java Servlet API, combined with Java Server Pages, was the basis of many large-scale web applications that are still in use today.
Writing web applications using Java Servlets can be a tedious undertaking with a steep learning curve. The very first book in the O’Reilly Head First series was a book on this topic, with the unwieldy full title:
Head First Servlets and JSP: Passing the Sun Certified Web Component Developer Exam
That book is now in its 2nd edition
Various frameworks arose to try to simplify the process, including the popular Spring framework for dependency injection.
A somewhat simpler framework is the Spark framework for Java (sometimes called SparkJava to differentiate it from the popular cluster computing platform called Apache Spark, with which it has nothing in common except the name)
You can read more about SparkJava at: