0

when i put this on my url "http:// localhost:8080 /ChickenTest/index.jsp" the browser show me this message "The requested resource (/ChickenTest/index.jsp) is not available." and eclipse console this message " No mapping found for HTTP request with URI [/ChickenTest/index] in DispatcherServlet with name 'dispatcherServlet'"

Controller:

package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import service.EggService;

@Controller
public class GeneralController {

    @Autowired
    EggService eggService;

    //jsp loaders
    @RequestMapping(value="/index")
    ModelAndView index(){
        ModelAndView mav = new ModelAndView();

        return mav;
    }

    //jsp loaders
    @RequestMapping(value="/Egg/indexEgg")
    ModelAndView indexEgg(){
        ModelAndView mav = new ModelAndView();

        return mav;
    }

    @RequestMapping(value="/Chicken/indexChicken")
    ModelAndView indexChicken(){
        ModelAndView mav = new ModelAndView();

        return mav;
    }

    @RequestMapping(value="/Farm/indexFarm")
    ModelAndView indexFarm(){
        ModelAndView mav = new ModelAndView();

        return mav;
    }
}

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

    <!-- Uncomment and your base-package here:
         <context:component-scan
            base-package="org.springframework.samples.web"/>  -->


    <mvc:annotation-driven />

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <!-- Example: a logical view name of 'showMessage' is mapped to '/WEB-INF/jsp/showMessage.jsp' -->
            <property name="prefix" value="/WEB-INF/view/"/>
            <property name="suffix" value=".jsp"/>
    </bean>

</beans>

web.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee"
         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>ChickenTest</display-name>

   <!--
        - Location of the XML file that defines the root application context.
        - Applied by ContextLoaderListener.
    -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring/application-config.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>


    <!--
        - Servlet that dispatches request to registered handlers (Controller implementations).
    -->
    <servlet>
        <servlet-name>dispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/mvc-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>dispatcherServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>
Vinoth Krishnan
  • 2,925
  • 6
  • 29
  • 34
Sam Derin
  • 115
  • 2
  • 4
  • 9
  • 1
    @RequestMapping(value="/Chicken/indexChicken") you are setting Chicken as mapping but in the url you use ChickenTest – fmodos Nov 07 '13 at 19:55
  • Thanks a lot, know i can see my mistake clearly. – Sam Derin Nov 07 '13 at 19:59
  • no problem, let me know if it worked, and then I will post an answer so you can mark it as accepted – fmodos Nov 07 '13 at 20:00
  • Yes that was the correct answer :) – Sam Derin Nov 07 '13 at 20:07
  • I find it very helpful to log the Spring logger statements for precisely this reason. At application start, Spring logs the RequestMappings (I think the logs are slightly different depending on which HandlerMapping you're implementing). Then you can compare the URI listed in the exception with the RequestMappings that were printed at application startup (literally, Ctrl+F right within the console). If you can't find it, there's probably been a typo somewhere. – Tony Card Nov 07 '13 at 20:15

2 Answers2

0

in mvc-config.xml , uncomment the code:

<!-- Uncomment and your base-package here:
         <context:component-scan
            base-package="org.springframework.samples.web"/>  -->

Add your base package, I think its controller or something. I think this is the issue.

Aditya Peshave
  • 667
  • 9
  • 26
0

You are accessing the url using the path ChickenTest but you have it mapped in your Controller as Chicken @RequestMapping(value="/Chicken/indexChicken")

Replace the RequestMapping to ChickenTest or access the url using Chicken.

fmodos
  • 4,472
  • 1
  • 16
  • 17