Mahmoud Saleh
Mahmoud Saleh

Reputation: 33605

org.springframework.web.servlet.DispatcherServlet noHandlerFound (No mapping found)

my jsps are under WEB-INF/jsp/ , and following is my web.xml:

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>Checkout</display-name>

  <servlet>
    <servlet-name>myservlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>myservlet</servlet-name>
    <url-pattern>*.action</url-pattern>
  </servlet-mapping>


</web-app>

and here's mapping of page product.jsp which i am trying to access:

@Controller
@RequestMapping("/product.action")
public class ProductController {

    /**
     * Show the product selection form
     * 
     * @return
     */
    @RequestMapping(method=RequestMethod.GET)
    public String get() {
        return "products.jsp";
    }

}

when trying to access the page from the following link:

http://localhost:8080/myapp/product.action

i am getting 404 in the browser, and i get the following warning in the console:

Jun 28, 2012 10:55:23 AM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/myapp/product.action] in DispatcherServlet with name 'myservlet'

am i missing something in the configuration ? please advise, thanks.

EDIT: i tried adding the viewResolver bean to applicationContext with no luck:

<?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:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">

    <context:component-scan base-package="com.myapp"/>



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


</beans>

Upvotes: 3

Views: 40826

Answers (8)

Backspace
Backspace

Reputation: 1

Solution for this error: org.springframework.web.servlet.DispatcherServlet noHandlerFound (No mapping found)

Simply follow these steps:

Right click on the project > Build Path > Configure Build path > Deployment Assembly > Add(right hand side) > Folder > Add your views folder > Apply and Close

Upvotes: 0

chandru
chandru

Reputation: 139

  1. Change this <url-pattern>*.action</url-pattern> to <url-pattern>/*.action</url-pattern>

  2. Check base-package name in .xml file when you learn from others tutorial

Hope it should work fine

Upvotes: 0

Malatesh K R
Malatesh K R

Reputation: 1

Check the package name spring-servlet.xml , if it is correctly spelled or not. That might be the issue. I faced while starting the Spring MVC

Upvotes: -1

Pradeep Kr Kaushal
Pradeep Kr Kaushal

Reputation: 1546

Follow the rule whatever Sunil has mentioned. I see one issue in your spring configuration xml that you don't have the

<mvc:annotation-driven />  

You need this to register the Controller along with

<context:component-scan base-package="com.myapp"/>

Upvotes: 3

user2542057
user2542057

Reputation: 1

İf you use viewResolver in context xml , you should change get method return statemant to "products" and be sure the folder hierarchy is right

Upvotes: 0

ASIK RAJA A
ASIK RAJA A

Reputation: 441

Use this class="org.springframework.web.servlet.view.UrlBasedViewResolver" instead of class="org.springframework.web.servlet.view.InternalResourceViewResolver"

in your application context bean.

Upvotes: 0

Mahmoud Saleh
Mahmoud Saleh

Reputation: 33605

problem was that the controller wasn't detected. i changed the base-package from com.myapp to com.myapp.controller, and it works fine now.

Upvotes: 1

Sunil Chavan
Sunil Chavan

Reputation: 3004

When you specify the RequestMapping, URI should not have extension. Dispatcher servlet will omit it from the request URI while searching for URI mapping.

Use @RequestMapping("/product") it should work.

Second thing when you are using view resolver just return the name of the JSP file. Do not append .jsp extension, InternalViewResolver will do it for you.

Upvotes: 2

Related Questions