Servlet API
22 questions in 7 subtopics.
Servlet lifecycle
Describe the servlet lifecycle. How many instances of a servlet exist, and what does that mean for instance fields?How does Spring MVC'sDispatcherServlet fit into the servlet lifecycle, and how does Spring Boot register it?Filters and listeners
A Spring Boot application has a custom servlet filter that logs requests, Spring Security's filter chain, and aHandlerInterceptor 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?What are servlet listeners such as ServletContextListener and HttpSessionListener used for?Write a servlet filter in Spring Boot that adds a request id to the MDC for logging and removes it afterwards.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?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
A filter logs the request body by readingrequest.getInputStream(), and then the controller fails with an empty body. Why, and how do you fix it?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
How does the servlet container track a user session, and which cookie attributes should be set for security?You are moving a stateful Spring MVC application withHttpSession data to Kubernetes with several replicas. What are your options?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
How does asynchronous request processing work in the Servlet API, and how does Spring MVC use it withDeferredResult?Your team wants to replace async servlet code and DeferredResult handling with virtual threads. What do you evaluate?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
Which embedded servlet containers does Spring Boot support, and how do you switch from Tomcat to Jetty?Under load, a Tomcat-based Spring Boot service rejects connections while CPU is only 40 percent. What Tomcat settings and causes would you investigate?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?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
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?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.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?No question matches these choices.