Getting default error page in Spring Boot web application

I keep getting a generic error page when running my Spring Boot app. The error message shows:

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

There was an unexpected error (type=Not Found, status=404).

I’m not sure what’s causing this issue. Here’s my project setup:

Maven dependencies (pom.xml):

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.5</version>
        <relativePath/>
    </parent>
    <groupId>com.example</groupId>
    <artifactId>WebDemo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>WebDemo</name>
    <description>Sample Spring Boot project</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.3.9</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
    </dependencies>
</project>

My servlet controller:

@WebServlet(urlPatterns = "/welcome")
public class WelcomeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
        req.getRequestDispatcher("/WEB-INF/views/welcome.jsp").forward(req, resp);
    }
}

JSP file content:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title>Welcome Page</title>
</head>
<body>
    <h1>Welcome to our site</h1>
    <p>This is the main page content.</p>
</body>
</html>

What could be wrong with my configuration?

Had the same problem when I started mixing servlet annotations with Spring Boot. You’re using @WebServlet which is old servlet API stuff, but Spring Boot wants you to use Spring MVC controllers. Spring Boot won’t scan for @WebServlet unless you turn on servlet component scanning.

Ditch the servlet and make a proper Spring controller instead. Use @Controller and @RequestMapping. Change your WelcomeServlet to @Controller public class WelcomeController and add a method with @GetMapping("/welcome"). Spring Boot will handle the routing correctly and you won’t see that whitelabel error anymore. Your JSP config looks good - just make sure the controller returns the right view name.

Your problem’s pretty straightforward - you’re mixing servlet annotations with Spring Boot, and they’re conflicting.

I hit this same issue migrating an old servlet app to Spring Boot. Spring Boot won’t scan @WebServlet annotations unless you tell it to.

Two ways to fix this:

Option 1: Add @ServletComponentScan to your main Spring Boot class. This makes Spring Boot find servlet annotations.

Option 2: Ditch the servlet and use Spring MVC instead (I’d go this route):

@Controller
public class WelcomeController {
    @GetMapping("/welcome")
    public String welcome() {
        return "welcome"; // returns welcome.jsp from views folder
    }
}

Then add this to application.properties:

spring.mvc.view.prefix=/WEB-INF/views/
spring.mvc.view.suffix=.jsp

I always pick option 2 - keeps everything consistent with Spring Boot patterns. The servlet way works but feels clunky when you’re already on Spring Boot.