Java Module 21
Jakarta EE web: Servlets and Tomcat interview questions
Interview questions on “Jakarta EE web: Servlets and Tomcat”: warm-ups, then what each harder question tests and how a good answer starts.
Warm-up questions
Short questions with short answers, each answered in full.
-
Fresher
What is the difference between a servlet container such as Tomcat and a Jakarta EE application server?
Answered in the lesson Jakarta EE, servlet containers and Tomcat 11
-
Fresher
What is a WAR file, and why are files under WEB-INF never served to browsers?
Answered in the lesson Your first servlet, web.xml and the WAR layout
Questions with model answers
What each question tests, the first step of a good answer and the follow-ups to expect.
-
Fresher to mid
A team copies a WAR that ran on Tomcat 9 into the webapps folder of Tomcat 11. Tomcat logs no error, but every servlet URL of the application answers 404. What happened, and what are the two ways to fix it?
- What it tests
- The javax to jakarta rename, how Tomcat finds annotated servlets, and choosing between recompiling and Tomcat's migration tool.
- First step
- Look inside the WAR before blaming Tomcat. Servlets built for Tomcat 9 import javax.servlet, while Tomcat 11 looks only for jakarta.servlet types and annotations. It therefore deploys the WAR, finds no servlet to map and answers 404 for every servlet URL, which is why nothing appears in the logs.
- Follow-ups
-
- How do you prove the cause in a minute without the source code?
- When is the webapps-javaee conversion the wrong long-term answer?
- Which libraries inside the WAR break in the same way?
From the lesson Jakarta EE, servlet containers and Tomcat 11
Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.Opening the model answers with your pass…
Model answers open with any MySmartCoPilot pass.
- Pro pass · 1 week₹79$2.99
- 30 days₹179$5.99
- 1 year₹1,699$45
One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.
Passes can’t be bought right now, so the model answers can’t be opened at the moment. If you have a pass, enter your licence key.
It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).
In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to mid
A scan of a shared test server finds Tomcat 11 answering on port 8080 on every network address, the examples and docs applications deployed, and port 8005 open on localhost with the default command. Rank these risks and say exactly what you change.
- What it tests
- Tomcat's default attack surface, the connector's address attribute, the shutdown port, and removing the sample applications, in order of risk.
- First step
- Rank by who can reach each thing. Port 8080 on every address is open to the whole network, so it comes first. The examples application adds code that shows and sets cookies. Port 8005 listens only on localhost, but any program on the server can stop Tomcat by sending SHUTDOWN.
- Follow-ups
-
- The team needs the Manager application on that server. What do you require first?
- How do you check each change from another computer?
- What changes once the server sits behind a reverse proxy?
From the lesson Jakarta EE, servlet containers and Tomcat 11
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
A WAR built against jakarta.servlet-api 6.1.0 passes every test and runs on Tomcat 11. On a server that still runs Tomcat 10.1 it deploys without errors, but one endpoint fails with NoSuchMethodError for HttpServletResponse.sendRedirect(String, int). Why, and how do you stop this reaching production?
- What it tests
- What provided scope means at run time, the API versions of the Tomcat lines, and a build that rejects methods the oldest target lacks.
- First step
- Provided means that the container's copy of the API is the one that runs. Tomcat 10.1 implements Servlet 6.0, and sendRedirect(String, int), which chooses the status of a redirect, arrived in Servlet 6.1. The code was compiled against 6.1, so the call is linked only when it first runs on 6.0, and fails there.
- Follow-ups
-
- Why did the deployment itself succeed?
- How do you make the build fail instead?
- What do you change in the code if Tomcat 10.1 must stay supported?
From the lesson Your first servlet, web.xml and the WAR layout
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to mid
An application maps one servlet to /api/, a second to .json and a third to /. Which servlet answers /api/orders.json, /reports/sales.json and /api? A teammate wants every .json file, including those under /api, served by the second servlet. What do you advise?
- What it tests
- The order of the mapping rules, how the servlet path and path info split a request, and designing URL patterns instead of fighting their precedence.
- First step
- Apply the rules in order: exact match, longest path prefix, extension, default. /api/orders.json and /api both match the prefix /api/, so the first servlet answers both, and /reports/sales.json matches no prefix, so the .json servlet answers it. No mapping lets an extension win inside a path prefix.
- Follow-ups
-
- What do getServletPath and getPathInfo return for each of the three requests?
- How would you serve the .json files under /api without moving them?
- What changes if the third servlet is mapped to /* instead of /?
From the lesson Your first servlet, web.xml and the WAR layout
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes