Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.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
org.springframework.web.servlet.DispatcherServlet noHandlerFound(未找到映射)_Spring_Jsp_Spring Mvc - Fatal编程技术网

org.springframework.web.servlet.DispatcherServlet noHandlerFound(未找到映射)

org.springframework.web.servlet.DispatcherServlet noHandlerFound(未找到映射),spring,jsp,spring-mvc,Spring,Jsp,Spring Mvc,我的jsp位于WEB-INF/jsp/下,下面是我的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> <servl

我的jsp位于WEB-INF/jsp/下,下面是我的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>
尝试从以下链接访问页面时:

http://localhost:8080/myapp/product.action
我在浏览器中收到
404
,在控制台中收到以下警告:

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'
配置中是否缺少某些内容? 请告知,谢谢

编辑:我尝试将viewResolver bean添加到applicationContext,但没有成功:

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

指定RequestMapping时,URI不应具有扩展名。在搜索URI映射时,DispatcherServlet将从请求URI中省略它

使用
@RequestMapping(“/product”)
它应该可以工作


当您使用视图解析器时,第二件事就是返回JSP文件的名称。不要附加.jsp扩展名,InternalViewResolver将为您执行此操作。

问题在于未检测到控制器。 我将基本包从
com.myapp
更改为
com.myapp.controller
,现在它工作正常。

使用此 class=“org.springframework.web.servlet.view.UrlBasedViewResolver” 而不是class=“org.springframework.web.servlet.view.InternalResourceViewResolver”


在应用程序上下文bean中。

如果在上下文xml中使用viewResolver,则应将get方法return statemant更改为“products”,并确保文件夹层次结构正确

遵循Sunil提到的规则。我在spring配置xml中看到一个问题,您没有

<mvc:annotation-driven />  

您需要这个来注册
控制器
以及


检查包名spring-servlet.xml是否拼写正确。这可能就是问题所在。我在启动Spring MVC时遇到了一个问题

我尝试了这个方法,但没有成功,我是否需要更改配置或web.xml映射中的任何内容?它给出了
404:说明请求的资源(/subscriptions/product)不可用。
当您遇到此错误时?看起来您的控制器处理程序方法已被调用,但返回的视图无法找到。如果是这样,当您返回视图名称时,它必须是相对路径。在浏览器中键入链接并按enter键时,我遇到此错误,您建议怎么办?您提到了资源“/subscriptions/product”的404错误,我想了解为什么路径包含“/subscriptions”?代码中没有提到它。底线检查两件事-1。是否使用URL调用控制器方法?您可以通过在控制台上显示一些消息来检查这一点。2.从handler方法返回的视图名称应该是WEB-INF的相对路径。例如,在上面的404错误中,product.jsp应该位于WEB-INF下的“subscriptions”文件夹中,handler方法应该返回/subscriptions/product
<mvc:annotation-driven />