Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

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.

7 questions: 2 warm-ups and 5 with model answers · Levels: Fresher to senior

Warm-up questions

Short questions with short answers, each answered in full.

  1. 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

  2. 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.

  1. 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

    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.

    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
  2. 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

    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
  3. 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

    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
  4. 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

    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
  5. Fresher to mid

    After a release, GET /orders/export answered 500 once and has answered 404 ever since, while the rest of the application works and catalina.out shows a normal deployment. What happened, where is the evidence, and how do you make this kind of failure visible at deployment next time?

    What it tests
    The servlet life cycle at the first request, Tomcat marking a servlet unavailable, its two log files, and load-on-startup with failCtxIfServletStartFails.
    First step
    A 500 followed by 404s is the mark of a servlet that failed while Tomcat created or initialised it for the first request: Tomcat marks it unavailable and stops calling it. The evidence is in logs/localhost.<date>.log, not in catalina.out: look for "Allocate exception" and "Marking servlet … as unavailable".
    Follow-ups

    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

All Java interview questions · The Java track

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.