1

why this is happening.

"WARNING: No mapping found for HTTP request with URI [/Spring3MVC/hello.html] in DispatcherServlet with name 'spring' "

my web.xml is

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
    <display-name>Spring3MVC</display-name>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>
</web-app>

spring.servlet.xml 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.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<context:component-scan base-package="net.viralpatel.spring3.controller"/>

<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
    <property name="prefix" value="/WEB-INF/jsp/"/>
    <property name="suffix" value=".jsp"/>
</bean>
</beans>

index.jsp is

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    <a href="hello.html">Say Hello</a>
</body>
</html>

hello.jsp is

<html>
<body>
    <h1>Message : ${message}</h1>   
</body>
</html>

HelloWorldController.java is

package net.viralpatel.spring3.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class HelloWorldController {

    @RequestMapping("/hello")
    public ModelAndView helloWorld() {

        String message = "Hello World, Spring 3.0!";
        return new ModelAndView("hello", "message", message);
    }
}

Why above warning are comming and not hitting controller.

org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/Spring3MVC/hello.html] in DispatcherServlet with name 'spring'.
Jens
  • 67,715
  • 15
  • 98
  • 113
anil
  • 11
  • 4

4 Answers4

0

try add <mvc:annotation-driven />.

david
  • 997
  • 7
  • 5
0

I think that the problem should be that the ModelAndView should be ModelAndView("hello.jsp","message",message) if not is it wouldn't match with the patter .jsp of your viewResolver.

belcex
  • 1
  • but with "hello" why not mapping. i have shown all code above. – anil Mar 17 '15 at 10:24
  • first @minion is right you need annotation-driven too. It doesn't mapping "hello" because in your view resolver you ask to resolve only the views with .jsp suffix, as your modelandview is requesting for a not .jsp suffix view it doesn't handle it. I think! – belcex Mar 18 '15 at 02:19
0

You would need <mvc:annotation-driven />. Add that after the <context:component-scan base-package="net.viralpatel.spring3.controller"/> . This would register spring defaults HandlerMapping and HandlerAdapter which is required to dispatch request to your controllers.

minion
  • 4,313
  • 2
  • 20
  • 35
0
<a href="hello.html">Say Hello</a>

This will look for a mapping /hello.html and this is not mapped any where in your controller this is the reason you get this error.

Note that all the requests goes through the dispatcherServlet and it will look for each url or action from the Request mapping's registered. If and url or resource mapping is not mapped or registered then you will get this error.

Secondly your viewResolver appends the .jsp after every pafe resolved. Thus when requested your actual page that spring will look will be hello.html.jsp

Ekansh Rastogi
  • 2,418
  • 2
  • 14
  • 23