JSP & Servlets for Beginners / Chapter 1 — Getting started and HTTP basics (lessons 1–4) / Lesson 1

Setting up Tomcat and your first servlet

Time needed: about 5 min (estimate)

☆ Read later

You can try the opening of this lesson without an account.

A servlet does nothing on its own

In a sentence, a servlet is "a Java class that receives an HTTP request".

The order is browser, then Tomcat, then your servlet.

What matters here is that the parts that speak HTTP and listen on TCP belong to Tomcat (the servlet container).

Spring Boot's java -jar app.jar brings up a server because Tomcat is simply bundled inside the jar; the thing running is the same.

In this series you prepare that Tomcat yourself, to make what happens inside visible.

javax or jakarta (the first stumble)

Get this wrong and nothing you do will work.

When Java EE moved to the Eclipse Foundation in 2019, the name javax could no longer be used, and everything was renamed to jakarta (the contents are largely the same; only the name changed).

javax.servlet.* is Tomcat 9 and earlier; jakarta.servlet.* is Tomcat 10 and later.

Most servlet articles online are from the javax era, so when a copied example does not work, try the substitution first.

It often fixes it outright.

Create a free account to keep reading

With an account you can read the rest of this lesson, take the quiz, and read every free lesson in this course. Lessons you answer correctly are recorded as complete.

Report a problem with this lesson

Log in to send a report.

Keyboard shortcuts

Keys available in a lesson
KeyAction
[ or Alt + ←Go to the previous lesson
] or Alt + →Go to the next lesson
?Open this list
EscClose this list

The keys do not work while the cursor is in a code editor or an input field.