在名称为'dispatcherServlet'的DispatcherServlet中找不到带有URI [/ChickenTest/index]的HTTP请求的映射 [英] No mapping found for HTTP request with URI [/ChickenTest/index] in DispatcherServlet with name 'dispatcherServlet'

查看:64
本文介绍了在名称为'dispatcherServlet'的DispatcherServlet中找不到带有URI [/ChickenTest/index]的HTTP请求的映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将其放在我的网址"http:// localhost:8080 /ChickenTest/index.jsp"上时,浏览器会向我显示此消息请求的资源(/ChickenTest/index.jsp)不可用." 并在Eclipse控制台中将此消息在名称为'dispatcherServlet'的DispatcherServlet中找不到带有URI [/ChickenTest/index]的HTTP请求的映射""

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'"

控制器:

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:

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>

推荐答案

您正在使用路径 ChickenTest 访问url,但已将其映射为Controller中的 Chicken . @RequestMapping(value="/Chicken/indexChicken")

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

RequestMapping替换为 ChickenTest ,或使用 Chicken 访问该网址.

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

这篇关于在名称为'dispatcherServlet'的DispatcherServlet中找不到带有URI [/ChickenTest/index]的HTTP请求的映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆