2017-09-21 67 views
0

我知道这个问题已经很多次了,我尝试了很多,但它不起作用。我有一些错误,我不知道如何处理它们。服务器看起来像不能识别jsp文件中定义的css文件和javascript文件。Org.springframework.web.servlet.dispatcherservlet nohandler发现没有找到映射

的web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="3.1" id="WebApp_ID" 
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 
xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
<display-name>spring-mvc-crud-demo</display-name> 
<welcome-file-list> 
    <welcome-file>Index.jsp</welcome-file> 
    <welcome-file>index.html</welcome-file> 
</welcome-file-list> 

<servlet> 
    <servlet-name>dispatcher</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/spring-mvc-crud-demo-servlet.xml</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 
<servlet-mapping> 
    <servlet-name>dispatcher</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping> 

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

<!-- Add support for component scanning --> 
<context:component-scan base-package="com.controller" /> 

<!-- Add support for conversion, formatting and validation support --> 
<mvc:annotation-driven /> 

<bean 
    class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="prefix" value="/WebContent/" /> 
    <property name="suffix" value=".jsp" /> 
</bean> 

控制器

package com.controller; 

import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 

@Controller 
@RequestMapping(value= "/intent", method= RequestMethod.POST) 
public class IntentController { 

@RequestMapping("/notepad") 
public String Notepad(){ 

    System.out.println("Notepad is redy"); 
    return "Index"; 
} 

错误 服务器没有看到css文件和javascript。

Sep 21, 2017 11:32:06 AM org.springframework.web.servlet.PageNotFound noHandlerFound 
WARNING: No mapping found for HTTP request with URI [/ApiAi/assets/css/noscript.css] in DispatcherServlet with name 'dispatcher' 
Sep 21, 2017 11:32:06 AM org.springframework.web.servlet.PageNotFound noHandlerFound 
WARNING: No mapping found for HTTP request with URI [/ApiAi/assets/js/jquery.min.js] in DispatcherServlet with name 'dispatcher' 
Sep 21, 2017 11:32:06 AM org.springframework.web.servlet.PageNotFound noHandlerFound 
WARNING: No mapping found for HTTP request with URI [/ApiAi/assets/css/mainCss.css] in DispatcherServlet with name 'dispatcher' 
Sep 21, 2017 11:32:06 AM org.springframework.web.servlet.PageNotFound noHandlerFound 
WARNING: No mapping found for HTTP request with URI [/ApiAi/assets/js/skel.min.js] in DispatcherServlet with name 'dispatcher' 
Sep 21, 2017 11:32:06 AM org.springframework.web.servlet.PageNotFound noHandlerFound 
WARNING: No mapping found for HTTP request with URI [/ApiAi/assets/js/util.js] in DispatcherServlet with name 'dispatcher' 
Sep 21, 2017 11:32:06 AM org.springframework.web.servlet.PageNotFound noHandlerFound 
WARNING: No mapping found for HTTP request with URI [/ApiAi/assets/js/main.js] in DispatcherServlet with name 'dispatcher' 
Sep 21, 2017 11:32:06 AM org.springframework.web.servlet.PageNotFound noHandlerFound 
WARNING: No mapping found for HTTP request with URI [/ApiAi/images/pic03.jpg] in DispatcherServlet with name 'dispatcher' 

回答

0

项目结构将有助于给出确切的答案。 虽然这可能不起作用,因为您尚未在您的servlet.xml文件中提供资源映射。通过使用以下标记提供适当的资源路径映射来再次尝试:

<mvc:resources mapping="/resources/**" location="/<your_path>" /> 
+0

是的,这是问题,并且我没有资源文件夹中的css文件 –

相关问题