Scrivio Interview library

Servlet API

22 questions in 7 subtopics.

Servlet lifecycle

ConceptFoundations7 min read
Describe the servlet lifecycle. How many instances of a servlet exist, and what does that mean for instance fields?
InternalsIntermediate6 min read
How does Spring MVC's DispatcherServlet fit into the servlet lifecycle, and how does Spring Boot register it?

Filters and listeners

ConceptFoundations6 min read
A Spring Boot application has a custom servlet filter that logs requests, Spring Security's filter chain, and a HandlerInterceptor that checks a tenant header. In what order do they run for one request, and why does a request rejected by Spring Security never reach the interceptor?
ConceptFoundations6 min read
What are servlet listeners such as ServletContextListener and HttpSessionListener used for?
CodingFoundations6 min read
Write a servlet filter in Spring Boot that adds a request id to the MDC for logging and removes it afterwards.
DebuggingIntermediate6 min read
Your custom authentication filter runs after Spring Security's filters and sees no user. How are filter orders decided in Spring Boot, and how do you fix it?
ScenarioAdvanced7 min read
Every service in your company writes its own servlet filters for request ids, logging and tenant headers, with slightly different behaviour. How would you standardise this?

Request and response

DebuggingFoundations7 min read
A filter logs the request body by reading request.getInputStream(), and then the controller fails with an empty body. Why, and how do you fix it?
DebuggingIntermediate7 min read
An error handler tries to set a 500 status and JSON body after part of the response has been written, and the client gets a truncated 200. Explain.

Sessions and cookies

ConceptFoundations6 min read
How does the servlet container track a user session, and which cookie attributes should be set for security?
DesignIntermediate6 min read
You are moving a stateful Spring MVC application with HttpSession data to Kubernetes with several replicas. What are your options?
ScenarioPrincipal6 min read
A large legacy web application stores significant state in HTTP sessions on application servers with session replication. You are moving it to containers over three years. What is your session strategy?

Async servlets

InternalsIntermediate6 min read
How does asynchronous request processing work in the Servlet API, and how does Spring MVC use it with DeferredResult?
ScenarioAdvanced6 min read
Your team wants to replace async servlet code and DeferredResult handling with virtual threads. What do you evaluate?
LeadershipPrincipal6 min read
Java web servers went from thread-per-request, to async servlets and reactive stacks, and now to virtual threads. What does this history mean for the programming model you would choose for new services today?

Servlet containers

ConceptFoundations5 min read
Which embedded servlet containers does Spring Boot support, and how do you switch from Tomcat to Jetty?
ScenarioIntermediate6 min read
Under load, a Tomcat-based Spring Boot service rejects connections while CPU is only 40 percent. What Tomcat settings and causes would you investigate?
DesignAdvanced5 min read
Your organisation runs Tomcat, Jetty and Undertow across different Spring Boot services. Should you standardise on one servlet container? How would you decide and migrate?
LeadershipPrincipal5 min read
Why did Java web deployment move from wars on shared application servers to executable jars with embedded containers, and what was lost?

JSP and tag libraries

ConceptFoundations6 min read
How is a JSP page processed by the servlet container, and what do JSTL tags (c:forEach, c:if, c:out) and Expression Language give you compared with scriptlets? What is the risk of ${param.name} in a page?
ScenarioIntermediate7 min read
A JSP application moving from Tomcat 9 to Tomcat 10.1 fails: pages show 'The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved' and custom tags throw ClassNotFoundException for javax.servlet.jsp.tagext.TagSupport. Explain and plan the migration.
LeadershipPrincipal6 min read
Your company still has internal tools built on JSP and custom tag libraries from the 2000s that work and are rarely changed, but few engineers know the technology. How would you decide what to do with them?