Scrivio Interview library
ScenarioIntermediate7 min read · updated 12 November 2026

A legacy app uses JSP views and server-side rendering, and a new team wants to build a single-page app with REST APIs on the same service. How would you structure the transition?

I would keep both styles in the same service during the transition: the existing @Controller classes keep serving JSP pages, and the new team builds @RestController APIs under a separate path such as /api/**. Screens move to the single-page app one at a time behind the same login, with security configuration shared but CSRF and session rules set per path. Because JSP does not work from an executable jar, the service stays a war, or the remaining pages move to Thymeleaf, before any packaging change.

Why this question is asked

Big-bang front-end rewrites are famous for running late, and while they run, the old screens still need fixes and the new ones deliver nothing to users. A gradual transition lets both teams work in the same service and lets users switch screen by screen. Interviewers ask this to see whether we can plan a migration that keeps the product working throughout, and whether we know the technical traps of JSP in modern Spring Boot. In this answer, we will look at the starting point and its constraints, structure the service so both styles live side by side, handle packaging, plan the screen-by-screen move, and set up security for pages and APIs together.

1The Starting Point and Its Constraints

The legacy application renders pages on the server. A @Controller puts data in a model and returns a view name, and JSP templates under WEB-INF turn that into HTML. Forms post back to controllers, and the user's login lives in an HTTP session identified by a cookie.

JSP has a few limitations in Spring Boot that shape the plan. JSPs are not supported when the application is packaged as an executable jar, because the container cannot find them inside the nested jar structure; they work when the application is packaged as a war, run either in an external container or as an executable war. Not every embedded container supports JSP either; Tomcat and Jetty do. And a Spring Boot 3 or 4 application uses the Jakarta namespace, so the JSTL and JSP libraries must be the Jakarta versions. None of this blocks a transition, but it means we should not change packaging casually.

2Structuring the Service So Both Styles Coexist

Spring MVC is happy to serve views and JSON from the same DispatcherServlet. We keep the existing @Controller classes unchanged and give the new team their own @RestController classes under /api/**. The single-page app itself is a set of static files, built by the front-end toolchain and served from /app/**.

Keeping paths separate is what makes everything else simple: security rules, caching, error handling and monitoring can all be set per path. One more piece is needed for the SPA's client-side routing. When a user refreshes on /app/orders/42, the server must return the SPA's index.html rather than a 404, so unknown paths under /app fall back to index.html.

Java
@RestController
@RequestMapping("/api/orders")
class OrderApi {
@GetMapping("/{id}") OrderDto get(@PathVariable long id) { return service.get(id); } // JSON
}
@Configuration
class SpaConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/app/**")
.addResourceLocations("classpath:/static/app/")
.resourceChain(true)
.addResolver(new PathResourceResolver() {
@Override
protected Resource getResource(String path, Resource location) throws IOException {
Resource file = location.createRelative(path);
return file.exists() && file.isReadable()
? file // a real asset such as main.js
: new ClassPathResource("/static/app/index.html"); // a client-side route
}
});
}
}
// GET /orders/list -> legacy JSP page (unchanged controller)
// GET /api/orders/42 -> {"id":42,"status":"PAID"}
// GET /app/orders/42 -> index.html of the SPA
Step throughOne service, two front ends
  1. BrowserJSP pages and the SPA, one session cookie
  2. Spring Securityone login; rules per path
  3. /orders/** @Controllerlegacy JSP views
  4. /app/** static filesSPA build output, index.html fallback
  5. /api/** @RestControllerJSON for the SPA
  6. Services and repositoriesshared by both

6 layers, from the top down. Step through them one at a time.

Notice why we use a resource resolver rather than a controller that forwards to index.html. A controller mapped to /app/** would also match the forward to /app/index.html and loop. The resolver serves real files such as /app/assets/main.js when they exist and falls back to index.html for anything else, so the SPA's router can take over.

3Moving Screens One at a Time

We migrate by screen, not by layer. For each screen, the new team builds the API it needs and the SPA page, then we switch the menu link from the JSP page to /app/... and watch error rates and user feedback. If something goes wrong, we switch the link back. Once a screen has run on the SPA without problems for a release or two, we delete its JSP and controller.

Order matters. Start with screens that are read-heavy and self-contained, such as a dashboard or a search page, to prove the deployment, login and API patterns. Leave complex multi-step forms, which depend most on server-side session state, for later. Because both front ends share one login, users move between old and new screens without signing in again, which is what makes the gradual approach acceptable to them.

The service layer is shared, so business rules stay in one place. The APIs should be designed for the SPA's needs, not as wrappers around the JSP controllers' models, because those models were shaped for templates.

4Security for Pages and APIs Together

The SPA runs in the same origin and the same browser session, so the simplest setup is that it uses the existing session cookie. That keeps one login, but it also means the APIs are open to cross-site request forgery, where another site makes the browser send a request with the user's cookie. So CSRF protection stays on for /api/**; the SPA reads the token from a cookie and sends it in a header. Recent Spring Security versions have a convenience for exactly this SPA setup (check your version); otherwise we use CookieCsrfTokenRepository.

Java
@Bean
SecurityFilterChain web(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests(a -> a
.requestMatchers("/app/**", "/login", "/css/**").permitAll()
.requestMatchers("/api/**").authenticated()
.anyRequest().authenticated())
.formLogin(Customizer.withDefaults()) // the existing login page
.csrf(c -> c.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()))
.exceptionHandling(e -> e.defaultAuthenticationEntryPointFor(
new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED), // APIs get 401, not a login redirect
PathPatternRequestMatcher.withDefaults().matcher("/api/**")));
return http.build();
}

Notice the entry point for /api/**. Without it, an expired session makes an API call return a 302 redirect to the login page, and the SPA receives HTML where it expected JSON. With it, the SPA gets a 401 and can send the user to the login page itself. The request matcher class has changed across Spring Security versions, so check your version for the exact name. If later the APIs are also called by other services with tokens, we add a separate SecurityFilterChain for those paths with stateless sessions and no CSRF, because there is no browser cookie to forge.

5Follow-up questions

Why not split the SPA and APIs into a new service from the start?

Because the APIs need the same data, business rules and login as the legacy pages. A new service would mean duplicating or extracting the domain logic and building single sign-on before delivering any screen. Starting in the same service is cheaper; the APIs can be extracted later if they grow a life of their own.

When would you replace JSP with Thymeleaf during the transition?

If we must move to executable jar packaging, if a security or Jakarta upgrade makes the JSP stack painful, or if many JSP screens will remain for years. Otherwise, rewriting pages that are going to be replaced by the SPA anyway is wasted effort.

How do you know the transition is finished?

When the menu has no links to JSP pages, the JSP controllers and templates have been deleted, and the war packaging and JSP dependencies can be removed. Tracking the number of remaining JSP views per release gives a simple progress measure.

6Conclusion

In this answer, we kept the legacy @Controller and JSP pages running while new @RestController APIs live under /api/** and the SPA under /app/** with an index.html fallback. We noted that JSP needs war packaging and Jakarta-compatible libraries, so packaging should not change mid-transition. Screens move one at a time behind the same login, starting with simple read-heavy ones, and security is shared, with CSRF kept on for cookie-based APIs and a 401 entry point for /api/** so the SPA never receives a login page instead of JSON.

What to say in the interviewAbout 100 seconds aloud

Open with

I wouldn't do a big-bang rewrite. I'd keep both styles in the same service: the existing @Controller classes and JSPs stay as they are, the new team adds @RestController APIs under /api, and the SPA build is served as static files under /app, with a resource resolver that falls back to index.html so deep links like /app/orders/42 return index.html.

Then, if they want more

One thing to check early is packaging: JSP doesn't work from an executable jar in Spring Boot, so the service has to stay a war, or the remaining pages move to Thymeleaf, and with Boot 3 everything has to be on the Jakarta versions of JSTL. Then we migrate screen by screen.

For each screen the team builds the API and the SPA page, we switch the menu link, watch errors, and delete the JSP after a release or two. I'd start with read-heavy, self-contained screens to prove the patterns, and leave complex multi-step forms for later.

Because the SPA is same-origin, it can reuse the existing session login, so users move between old and new screens without logging in again. That means CSRF stays on for the APIs, with the token in a cookie the SPA sends back as a header.

I'd also make /api return 401 instead of redirecting to the login page, so the SPA never gets HTML when it expects JSON. If other services later call the APIs with tokens, they get their own stateless security chain.

About this answer

Last updated
12 November 2026
Versions it names
Spring Boot 3
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "A legacy app uses JSP views and server-side rendering, and a new team wants to build a...": https://scrivio-interview-library.netlify.app/spring-boot/mvc-architecture/a167e682f5/