JSP and Servlets
How Java web apps work underneath: Servlets, JSP, sessions and the MVC pattern.
Start here
Servlets
- Servlets and JSP: What a Servlet Container Does and How a JSP Becomes a Servlet
A JSP looks like HTML with a little Java, yet Tomcat runs it as a servlet. See what a servlet container does for each request, what the generated hello_jsp.java looks like, what a .war holds, and Tomcat vs TomEE.
- Set Up Tomcat 11 and a Maven Web Project in IntelliJ IDEA
Set JAVA_HOME, install Tomcat 11 on a free port, create a Jakarta EE web application with Maven in IntelliJ IDEA, read its folders and pom.xml, and run it on Tomcat.
- The Servlet Request Lifecycle: @WebServlet, web.xml, init, doGet and destroy
A servlet is a Java class that answers a URL. Follow one request through Tomcat, map servlets with @WebServlet and web.xml, build a page from a list, and watch init, doGet and destroy run.
- Servlet Request Parameters, and Forward vs Redirect
Read ?name=Emma with getParameter, then hand a request on two ways: a forward keeps one request and its attributes, a redirect makes the browser ask again and the attribute is gone.
- Run a Java Web App in Docker: Tomcat 11 With One Compose Command
Run a servlet project without installing Tomcat: one docker compose command builds the WAR with Maven on Java 25, starts Tomcat 11 in a container, and serves the app on localhost:8090.
- Sessions, Cookies and Filters in Java Servlets: Log In Once, Stay Logged In
HTTP treats every request as a stranger. A session on the server, a JSESSIONID cookie in the browser and one LoginFilter on /* let you log in once and keep every page behind the login.
JSP
- Servlets and JSP: What a Servlet Container Does and How a JSP Becomes a Servlet
A JSP looks like HTML with a little Java, yet Tomcat runs it as a servlet. See what a servlet container does for each request, what the generated hello_jsp.java looks like, what a .war holds, and Tomcat vs TomEE.
- JSP Scripting: Expressions, Scriptlets, Declarations, Comments and Includes
The JSP tags you'll read in older Java web apps: expressions, scriptlets, declarations, page imports, two kinds of comment, and the include directive versus the jsp:include action, each shown with what Tomcat turns it into.
- JavaBeans and JSP Scopes: Page, Request, Session and Application
A Student bean filled from a form with jsp:useBean and setProperty, then one Counter class kept in four scopes. Three visits, two browsers and an include page show exactly who sees which number.
- JSP Expression Language Step by Step: ${...} for Beans, Maps, Lists, Params and Scopes
Expression Language prints a value in a JSP with ${...} and no Java on the page. Read a Student bean, a price map, a tag list and ?city=Boston, run small checks, and see the order EL searches the scopes.
- JSTL Core Tags: c:set, c:out, c:if, c:choose and c:forEach
Five JSTL core tags let a JSP decide and repeat with no Java on the page. Add the jars to pom.xml, then use c:set, c:out (and see why it is safer than plain EL), c:if, c:choose and c:forEach on three orders.
- JSTL Functions and Formatting: fn:length, fn:toUpperCase, fn:contains, fmt:formatNumber and fmt:formatDate
Raw values in, friendly values out: fn:length counts three students, fn:toUpperCase and fn:contains work on text, and fmt turns 1234.5 into $1,234.50 and a Date into 19 October 2026, in the browser's language.
- Maintaining and Migrating Legacy JSP With AI: Explain the Page, Refactor to a DAO, Servlet and JSTL, Then Move It to React
One tangled orders.jsp glues the status into SQL, opens a connection it never closes, mixes Java into HTML and styles inline. Three prompts explain it, refactor it to a DAO, a servlet and an EL plus JSTL page, and migrate the table to React 19 with TypeScript. The review catches two draft bugs: a javax taglib URI and an unescaped customer name.
MVC
- MVC and the Front Controller With Servlets and JSP
A Book model, a BookController servlet and a books.jsp view behind WEB-INF show MVC in plain Java. Then one servlet on /app/* becomes a front controller, the idea Spring's DispatcherServlet grew from.
- Forms With JSP and Servlets: Handle the POST and Validate on the Server
Post a sign-up form straight to a JSP and anything gets accepted. Post it to a servlet instead: doPost checks name and email, forwards back with errors and the typed values, or on to the welcome page.
- Mini App With Servlets and JSP: Login, Logout and a Shared Web Template
Four pages and one template: a login form that posts to a servlet, a session that remembers the user, a filter that guards home.jsp and account.jsp, and a logout that ends it, plus when each step forwards or redirects.
- SQLite and a JDBC Connection Pool in a Java Web App
A whole database in one file, studyeasy.db, and a Java web app that talks to it: one HikariCP pool, a @WebListener that opens it and runs schema.sql at startup, and a /db-check servlet that borrows a connection.
- Users CRUD With Servlets and JSP, Part 1: Add and List Through a DAO
Fill an empty users table from a form and list every row: UserController picks the page, UserDao holds all the SQL, SaveUserServlet inserts and redirects, and a JSTL table shows the rows. Plus why every value goes in as a ?.
- Users CRUD With Servlets and JSP, Part 2: Update and Delete
Edit and Delete links on every row: one form does add and edit with a hidden id, a confirm page asks before deleting, and only a POST changes the database, then redirects back to the list.
