Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在名为';dispatcherServlet';_Java_Jsp_Spring Mvc - Fatal编程技术网

Java 在名为';dispatcherServlet';

Java 在名为';dispatcherServlet';,java,jsp,spring-mvc,Java,Jsp,Spring Mvc,当我把它放在我的url上时,“http://localhost:8080/ChickenTest/index.jsp”浏览器向我显示此消息,“请求的资源(/ChickenTest/index.jsp)不可用。”和eclipse控制台此消息“未找到具有URI的http请求的映射[/ChickenTest/index]在名为“DispatcherServlet”的DispatcherServlet中 控制器: package controller; import org.springframewo

当我把它放在我的url上时,
“http://localhost:8080/ChickenTest/index.jsp”
浏览器向我显示此消息,“请求的资源(/ChickenTest/index.jsp)不可用。”和eclipse控制台此消息“未找到具有URI的http请求的映射[/ChickenTest/index]在名为“DispatcherServlet”的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:

<?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>

奇肯特
上下文配置位置
类路径:spring/application-config.xml
org.springframework.web.context.ContextLoaderListener
调度员服务
org.springframework.web.servlet.DispatcherServlet
上下文配置位置
/WEB-INF/mvc-config.xml
1.
调度员服务
/

在mvc-config.xml中,取消对代码的注释:

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

添加您的基本包,我想是它的控制器或其他东西。
我认为这就是问题所在。

您正在使用路径ChickenTest访问url,但您在控制器中将其映射为Chicken
@RequestMapping(value=“/Chicken/indexChicken”)


RequestMapping
替换为ChickenTest或使用Chicken访问url

@RequestMapping(value=“/Chicken/indexChicken”)您将Chicken设置为映射,但在url中使用ChickenTest非常感谢,知道我可以清楚地看到我的错误。没问题,请告诉我它是否有效,然后我将发布一个答案,这样您就可以将其标记为acceptedYes,这是正确的答案:)我发现记录Spring logger语句非常有帮助,正是因为这个原因。在应用程序启动时,Spring会记录RequestMappings(我认为日志会略有不同,具体取决于您实现的HandlerMapping)。然后,您可以将异常中列出的URI与应用程序启动时打印的RequestMappings进行比较(确切地说,控制台中的Ctrl+F)。如果你找不到的话,可能是某个地方有错别字。