Spring boot: Path with “WEB-INF” or “META-INF”

Warning Path with “WEB-INF” or “META-INF”

Today I faced an issue while developing a spring boot demo app. I Have created a spring boot project, added UserController, and updated the application.properties file with the following configuration.

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

The complete project structure looks like below.

WEB-INF or META-INF

These configurations are used to tell spring where to look for JSP files. We can configure it in our Springboot application class as well as below.

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;

@SpringBootApplication
public class DemoappApplication implements WebMvcConfigurer{

	public static void main(String[] args) {
		SpringApplication.run(DemoappApplication.class, args);
	}

	@Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/view/");
        resolver.setSuffix(".jsp");
        resolver.setViewClass(JstlView.class);
        registry.viewResolver(resolver);
    }
}

UserController.java

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/user")
public class UserController {

	@GetMapping("/add")
	public String dispalyAddUser(Model model) {

		return "add-user";
		
	}
}

ad-user.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>add user</title>
</head>
<body>
	
</body>
</html>

After creating all the required files, I started the application and access the URL http://localhost:8080/user/add. I was expecting an empty HTML page with the title “add user” based on the configuration, but in response displayed an error page.

Path with WEB-INF or META-INF

Therefore I checked the console log and found the warning “WARN 3676 — [nio-8080-exec-1] o.s.w.s.r.ResourceHttpRequestHandler : Path with “WEB-INF” or “META-INF”: [WEB-INF/view/add-user.jsp]”.

Root Cause

The class requires to resolve the JSP path is available in the tomcat jasper package and the dependency is not added in pom.xml. Hence, the spring boot application is not able to resolve the JSP path.

Solution

The dependent classes are available in tomcat jasper. Add tomcat jasper dependency in the pom.xml file.

<dependency>
  <groupId>org.apache.tomcat.embed</groupId>
  <artifactId>tomcat-embed-jasper</artifactId>
</dependency>

You can copy this from the maven repository as well.

Once you add the above dependency in the pom.xml file and re-run the application it will work as expected.

Recommended Read

Java Exception in detail with example
Java Exception Test

Happy Learning !!

1 thought on “Spring boot: Path with “WEB-INF” or “META-INF””

Leave a Comment