RequestMappingHandlerMapping : Did not find handler method for [/WEB-INF/jsp/home.jsp]

11,341

Solution 1

While using Maven and I was missing these dependencies -

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>

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

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
    </dependency>

I have little to no knowledge on Gradle you can try to remove javax-servlet and jsp dependencies. As you already have tomcat and web dependencies added. Also if you are using, jstl, you can use this dependency -

compile('javax.servlet:jstl')

Solution 2

  • Adding jasper dependency worked for me.
  • The embedded tomcat needs the jasper dependency to render the jsp views in Spring boot application.

    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
    </dependency>
    
  • And if you require to write iteration, control statements in your jsp pages then also include JSTL i.e JSP Standard Tag Library in your pom.xml as follows:

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
    </dependency>
    
Share:
11,341

Related videos on Youtube

Ng Sharma
Author by

Ng Sharma

Java Developer, Passionate by @java, @blockchain,@reactjs and @Solidity . Interested in Java science &amp; love {open source}. Twitter LinkedIn

Updated on June 04, 2022

Comments

  • Ng Sharma
    Ng Sharma almost 2 years

    May be everything okay but i'm getting error. basically i'm add view resolver properties in application properties file, then run this project and open a browser, browser show this error Whitelabel Error Page 404 file not found. I don't understand help me and suggested how to resolve this problem , i'm newbie in Spring Boot.in this blow my project detail's .

    Error

     2018-04-07 12:11:51.661 DEBUG 3740 --- [nio-8080-exec-1] o.s.w.s.v.ContentNegotiatingViewResolver : Returning [org.springframework.web.servlet.view.InternalResourceView: name 'home'; URL [/WEB-INF/jsp/home.jsp]] based on requested media type 'text/html'
    2018-04-07 12:11:51.661 DEBUG 3740 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Rendering view [org.springframework.web.servlet.view.InternalResourceView: name 'home'; URL [/WEB-INF/jsp/home.jsp]] in DispatcherServlet with name 'dispatcherServlet'
    2018-04-07 12:11:51.661 TRACE 3740 --- [nio-8080-exec-1] o.s.w.servlet.view.InternalResourceView  : Rendering view with name 'home' with model {} and static attributes {}
    2018-04-07 12:11:51.684 DEBUG 3740 --- [nio-8080-exec-1] o.s.w.servlet.view.InternalResourceView  : Forwarding to resource [/WEB-INF/jsp/home.jsp] in InternalResourceView 'home'
    2018-04-07 12:11:51.687 TRACE 3740 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Bound request context to thread: org.apache.catalina.core.ApplicationHttpRequest@3087f725
    2018-04-07 12:11:51.687 DEBUG 3740 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/WEB-INF/jsp/home.jsp]
    2018-04-07 12:11:51.687 TRACE 3740 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Testing handler map [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@7ba6a25a] in DispatcherServlet with name 'dispatcherServlet'
    2018-04-07 12:11:51.687 TRACE 3740 --- [nio-8080-exec-1] o.s.w.s.handler.SimpleUrlHandlerMapping  : No handler mapping found for [/WEB-INF/jsp/home.jsp]
    2018-04-07 12:11:51.687 TRACE 3740 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Testing handler map [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping@6d6680cb] in DispatcherServlet with name 'dispatcherServlet'
    2018-04-07 12:11:51.687 DEBUG 3740 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /WEB-INF/jsp/home.jsp
    2018-04-07 12:11:51.690 DEBUG 3740 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Did not find handler method for [/WEB-INF/jsp/home.jsp]
    2018-04-07 12:11:51.690 TRACE 3740 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Testing handler map [org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping@1a14f49d] in DispatcherServlet with name 'dispatcherServlet'
    2018-04-07 12:11:51.690 TRACE 3740 --- [nio-8080-exec-1] o.s.w.s.h.BeanNameUrlHandlerMapping      : No handler mapping found for [/WEB-INF/jsp/home.jsp]
    2018-04-07 12:11:51.690 TRACE 3740 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Testing handler map [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@7b19df79] in DispatcherServlet with name 'dispatcherServlet'
    2018-04-07 12:11:51.690 DEBUG 3740 --- [nio-8080-exec-1] o.s.w.s.handler.SimpleUrlHandlerMapping  : Matching patterns for request [/WEB-INF/jsp/home.jsp] are [/**]
    2018-04-07 12:11:51.691 DEBUG 3740 --- [nio-8080-exec-1] o.s.w.s.handler.SimpleUrlHandlerMapping  : URI Template variables for request [/WEB-INF/jsp/home.jsp] are {}
    2018-04-07 12:11:51.692 DEBUG 3740 --- [nio-8080-exec-1] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapping [/WEB-INF/jsp/home.jsp] to HandlerExecutionChain with handler [ResourceHttpRequestHandler [locations=[class path resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/], ServletContext resource [/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@73797478]]] and 1 interceptor
    2018-04-07 12:11:51.692 TRACE 3740 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Testing handler adapter [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter@44abba94]
    2018-04-07 12:11:51.692 TRACE 3740 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Testing handler adapter [org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter@f0e0b58]
    2018-04-07 12:11:51.693 DEBUG 3740 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Last-Modified value for [/WEB-INF/jsp/home.jsp] is: -1
    2018-04-07 12:11:51.693 TRACE 3740 --- [nio-8080-exec-1] o.s.w.s.r.ResourceHttpRequestHandler     : Path contains "WEB-INF" or "META-INF".
    2018-04-07 12:11:51.693 TRACE 3740 --- [nio-8080-exec-1] o.s.w.s.r.ResourceHttpRequestHandler     : Ignoring invalid resource path [WEB-INF/jsp/home.jsp]
    2018-04-07 12:11:51.693 TRACE 3740 --- [nio-8080-exec-1] o.s.w.s.r.ResourceHttpRequestHandler     : No matching resource found - returning 404
    2018-04-07 12:11:51.693 DEBUG 3740 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
    2018-04-07 12:11:51.693 TRACE 3740 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Cleared thread-bound request context: org.apache.catalina.core.ApplicationHttpRequest@3087f725
    

    build.gradle

        buildscript {
        ext {
            springBootVersion = '2.0.1.RELEASE'
        }
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        }
    }
    
    apply plugin: 'java'
    apply plugin: 'eclipse-wtp'
    apply plugin: 'org.springframework.boot'
    apply plugin: 'io.spring.dependency-management'
    apply plugin: 'war'
    
    group = 'com.ethxpay.book.ticket.app'
    version = '0.0.1-SNAPSHOT'
    sourceCompatibility = 1.8
    targetCompatibility = 1.8
    
    repositories {
        mavenCentral()
    }
    
    configurations {
        providedRuntime
    }
    
    dependencies {
        compile('org.springframework.boot:spring-boot-starter-data-jpa')
        compile('org.springframework.boot:spring-boot-starter-web')
        compile('org.apache.tomcat.emded:tomcat-embed-japer')
    
        runtime('org.springframework.boot:spring-boot-devtools')
        runtime('mysql:mysql-connector-java')
    
        providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
    
        testCompile('org.springframework.boot:spring-boot-starter-test')
    
        compile group: 'javax.servlet', name: 'servlet-api', version: '3.0' 
        compile group: 'javax.servlet.jsp', name: 'jsp-api', version: '2.1' 
    }
    

    application.properties

        #Database Properties
    spring.datasource.url=jdbc:mysql://localhost:3306/customerdb?useSSL=false
    spring.datasource.username=root
    spring.datasource.password=root
    
    #View Resolver
    spring.mvc.view.prefix=/WEB-INF/jsp/
    spring.mvc.view.suffix=.jsp
    
    #JPA/Hibernate properties
    spring.jpa.show-sql=true
    spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
    spring.jpa.hibernate.ddl-auto=update
    spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
    
    #Log
    logging.level.org.hibernate.SQL:debug
    logging.level.org.springframework: TRACE
    logging.level.com: TRACE
    

    Controller Class

        @RestController
    public class EmployeeController {
    
        @Autowired
        private EmployeeService employeeService;
    
        @RequestMapping("/")
        public ModelAndView index() {
            return new ModelAndView("home");
        }
    
        @PostMapping("/createEmp")
        public void createEmp(HttpServletRequest request, HttpServletResponse response) {
            Employee emp = new Employee(request.getParameter("name"), request.getParameter("tel"),
                    request.getParameter("address"), Double.parseDouble(request.getParameter("sal")));
    
            employeeService.create(emp);
        }
    }
    

    Project-Seed

    enter image description here

    • SeverityOne
      SeverityOne about 6 years
      Don't put your JSP in WEB-INF. It should be one level higher.
    • Ng Sharma
      Ng Sharma about 6 years
      i don't understand please tell me more details @SeverityOne
    • SeverityOne
      SeverityOne about 6 years
      Your JSPs should be in the src/main/webapp folder, not in WEB-INF. In addition, the createEmp method should return a ModelAndView instance. Whether this would solve your problem I can't say (yet), but these two points strike me as incorrect.
    • Ng Sharma
      Ng Sharma about 6 years
      did not work @ServerityOne
  • Seetharaman Mohan
    Seetharaman Mohan about 5 years
    After adding jasper and jstl dependencies, the White Label issue got resolved in my spring boot web application. Thank you Ajay Kumar.