org.springframework.web.servlet.PageNotFound noHandlerFound; WARNING: No mapping found for HTTP request with URI in DispatcherServlet
Asked Answered
H

6

5

I went through many forums and blogs to get the answer but couldn't get any useful tip or advice. So please if anybody can help in below issue it would be a great help.

I am getting the below Warning and error when tried to connect to http://localhost:8080/SpringApp/hello :

INFO: Server startup in 6935 ms
Jul 19, 2014 11:15:42 AM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/SpringApp/] in DispatcherServlet with name 'HelloWeb'
Jul 19, 2014 11:16:29 AM com.example.java.HelloController printHelloWorld
INFO: HelloController : printHelloWorld : ENTER
Jul 19, 2014 11:16:29 AM com.example.java.HelloController printHelloWorld
INFO: HelloController : printHelloWorld : EXIT
Jul 19, 2014 11:16:29 AM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/SpringApp/WEB-INF/jsp/hello.jsp] in DispatcherServlet with name 'HelloWeb'

because of this I am getting HTTP Status 404 error in Tomcat.

The whole data is provided below:

The web.xml file is :

<display-name>Spring MVC Application</display-name>
<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<servlet>
    <servlet-name>HelloWeb</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/HelloWeb-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>HelloWeb</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

The HelloWeb-Servlet.xml file is :

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd 
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<context:component-scan base-package="com.example.java"></context:component-scan>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/"></property>
    <property name="suffix" value=".jsp"></property>
</bean>
<context:annotation-config/>
<mvc:annotation-driven/>
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"></bean>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"></bean>
</beans>

The HelloController.java file is :

package com.example.java;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/hello")
public class HelloController {

    protected final Log logger = LogFactory.getLog(getClass());

    @RequestMapping(method=RequestMethod.GET)
    public String printHelloWorld(ModelMap model){
        logger.info("HelloController : printHelloWorld : ENTER");
        model.addAttribute("message", "Hello Sumit");
        logger.info("HelloController : printHelloWorld : EXIT");
        return "hello";
    }
}
Heteronomy answered 19/7, 2014 at 6:19 Comment(0)
R
2

See My Answer Here= https://www.youtube.com/watch?v=-AtPAeSWz-o

The following worked for me. As you can see from the above YouTube video, I already tested it and it works.

Directory Structure:

Make sure your directory structure matches this.

enter image description here

web.xml:

A few things to note: The <url-pattern> should be <url-pattern>/<url-pattern> because when the app first starts up, it tries to connect to localhost:8080/YourAppName/ and not localhost:8080/YourAppName/homePage.

enter image description here

HelloController.java:

enter image description here

HelloWeb-servlet.xml enter image description here enter image description here

Rhizo answered 26/5, 2017 at 15:58 Comment(0)
M
6

Firstly, the file name should be HelloWeb-servlet.xml (servlet 's' lowercase). If still you have some problem try adding

<mvc:default-servlet-handler/>

in HelloWeb-servlet.xml

Moffett answered 6/8, 2014 at 2:9 Comment(1)
'<mvc:default-servlet-handler/>' saved my daySnitch
H
3

I have Almost Spend 20 hrs solving this issue for Annotation based approach

this error means your DipatcherServlet didn't find the controller class

please place the Controller class or the class with annotation @RestController/@Controller in the child package of the Configuration class or class with annotaion @Component Scan

ex org.example.app ------> configuration class org.example.app.controller------->controller class

Heerlen answered 4/9, 2016 at 9:54 Comment(0)
R
2

See My Answer Here= https://www.youtube.com/watch?v=-AtPAeSWz-o

The following worked for me. As you can see from the above YouTube video, I already tested it and it works.

Directory Structure:

Make sure your directory structure matches this.

enter image description here

web.xml:

A few things to note: The <url-pattern> should be <url-pattern>/<url-pattern> because when the app first starts up, it tries to connect to localhost:8080/YourAppName/ and not localhost:8080/YourAppName/homePage.

enter image description here

HelloController.java:

enter image description here

HelloWeb-servlet.xml enter image description here enter image description here

Rhizo answered 26/5, 2017 at 15:58 Comment(0)
S
0

I was also getting the same error.My mistake was that My Project name and servlet name were different.When I changed my servlet name to proj name ,I stopped getting this error.

Scissor answered 31/5, 2016 at 4:55 Comment(0)
K
0

My Mistake was that I put my Controller packages and class under src/main/resources, it should have been in src/main/java.

Knorring answered 23/5, 2020 at 11:36 Comment(0)
G
0

use jstl-1.2.1.jar lib in spring-mvc for servlet

Grettagreuze answered 10/6, 2022 at 18:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.