在DispatcherServlet中找不到带有URI []的HTTP请求的映射,名称为“spring”

时间:2015-05-28 00:14:59

标签: java jquery ajax spring-mvc

我在spring框架中的viewresolver中遇到问题。

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


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

  <mvc:annotation-driven/>   

  <!--  <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name="prefix" value="" />
      <property name="suffix" value="InfraUI.html" />
  </bean>  --> 

 <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
         <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>          
       <property name="prefix" value="" />  
      <property name="suffix" value="Home.html" />
      <property name="order" value="0" />
   </bean>  
   <mvc:resources mapping="/WebContent/**" location="/WebContent/" />

   <!-- Initialization for data source -->
   <bean id="dataSource"  class="org.springframework.jdbc.datasource.DriverManagerDataSource">
      <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
      <property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:XE"/>
      <property name="username" value="XXXX"/>
      <property name="password" value="XXXX"/>
   </bean>


   <!-- Definition for JDBCTemplate bean -->
   <bean id="JDBCTemplate" class="com.dao.JDBCTemplate">
      <property name="dataSource"  ref="dataSource" />    
   </bean>      
</beans>

的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <display-name>E-Health3</display-name>

    <welcome-file-list>
        <welcome-file>InfraUI.html</welcome-file>
    </welcome-file-list>
      <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <!-- <init-param>
        <param-name>contextConfiguration</param-name>
        <param-value>/WebContent/WEB-INF/spring-servlet.xml</param-value></init-param> -->
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping> 

</web-app>

控制器:

package com.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller    
    public class CustomController {

        @RequestMapping(value="/",params="abcd")
        public void test() {
            System.out.println("in test method of conroller");
        }
        }

我正在尝试的是将来自html页面的请求发送到spring控制器并将一个JSON从spring控制器返回到请求页面。但是现在我通过tomcat构建了这个错误,

org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/CONTEXTROOT/] in DispatcherServlet with name 'spring'

1 个答案:

答案 0 :(得分:0)

将此添加到您的nav { width: 100%; background: #202125; box-shadow: 0px 1px 0px 0px #2C2E32; padding: 0; overflow: hidden; } nav ul { list-style: none; overflow: hidden; margin: 0; padding: 0; } nav ul li { float: left; position: relative; padding: 20px 0; width: 120px; text-align: center; } nav ul li.active { background: #F5A623; } svg path { fill: #fff !important; } nav ul li .svg-container { width: 20px; height: 10px; margin: 0 auto; padding: 0 auto; } nav ul li img { display: block; margin: 0 auto; padding: 0 auto; width: 100%; } nav ul li span { display: inline-block; color: #fff; padding-top: 10px; } nav ul li a { position: absolute; top: 0; left: 0; height: 80px; width: 120px; text-indent: -5000em; }

web.xml

另外,您的请求是什么样的?