0

i'm trying to run a simple spring mvc project, but i get this error WARNING: No mapping found for HTTP request with URI [ ] in DispatcherServlet with name

i've tried several solutions but still not working

here is the code web.xml

<?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_3_0.xsd" id="WebApp_ID" version="3.0">
    <display-name>TestSpring2</display-name>
    <listener>
        <listener- class="">org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring-mvc.xml</param-value>
    </context-param>
    <servlet>
        <servlet-name>action</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/application-servlet-config.xml</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>*.aspx</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

servlet-mvc.xml

<?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" 
        xmlns:mvc="http://www.springframework.org/schema/mvc" 
        xsi:schemaLocation="http://www.springframework.org/schema/mvc   
     http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
        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">

    <bean class="edu.spring.dao.ProduitImpl" id="produitdao" init-method="init"></bean>

    <bean class="edu.spring.service.ProduitMetierImpl" id="produitservice">
        <property name="dao" ref="produitdao"></property>
    </bean>

    <mvc:annotation-driven />

    <context:component-scan base-package="edu.spring.controller"/>

</beans>

application-servlet-config.xml

<?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"
xmlns:sec="http://www.springframework.org/schema/security"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/security      http://www.springframework.org/schema/security/spring-security-2.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">

<mvc:annotation-driven />

<context:component-scan base-package="edu.spring.controller"/>

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

ProduitController.java

package edu.spring.controller;

import java.util.ArrayList;
import java.util.List;

 import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import edu.spring.dao.Produit;
import edu.spring.service.ProduitMetier;

@Controller
 public class ProduitController  {

@Autowired
ProduitMetier services;

@RequestMapping(value="/index")
public String pageIndex(Model model){

    model.addAttribute("listeProduit", services.getAllProduits());
    return "produits";
}


@RequestMapping(value="/searchProduct")
public String searchProduct(Model model,@RequestParam(value ="idProduit") Long id){

    List<Produit> liste = new ArrayList<Produit>();
    liste.add(services.getProduitById(id));
    model.addAttribute("listeProduit", liste);
    model.addAttribute("idProduit", id);

    return "produits";
}

@RequestMapping(value="/addProduct")
public String addProduct(Model model,Produit p){

    services.addProduit(p);
    model.addAttribute("listeProduit", services.getAllProduits());

    return "produits";
}


@RequestMapping(value="/deleteProduit")
public String supprimerProduit(Model model,@RequestParam Long id){
    services.deleteProduit(id);
    model.addAttribute("listeProduit", services.getAllProduits());
    return "produits";
    }   
}
sergiomse
  • 775
  • 12
  • 18
ahmed
  • 11
  • 7
  • 1
    what is the URL that you are trying to hit? – Aniket Thakur Jan 10 '16 at 06:45
  • @Aniket actually both URLs [TestsSpring2/Pages/produits.jsp] and [TestsSpring2/index.jsp] give me the same error – ahmed Jan 10 '16 at 10:08
  • Yup so there is no mapping for those URL As per your code yo should try `TestsSpring2/index.aspx` or `TestsSpring2/searchProduct.aspx` and you should get produits.JSP with corresponding models in response. – Aniket Thakur Jan 10 '16 at 11:15
  • ok i changed the URL pattern of DispatcherServlet to `*.jsp` and still getting the same error – ahmed Jan 10 '16 at 11:49

0 Answers0