Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.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
Spring 未找到具有URI警告的HTTP请求的映射导致的CSS问题_Spring_Spring Mvc - Fatal编程技术网

Spring 未找到具有URI警告的HTTP请求的映射导致的CSS问题

Spring 未找到具有URI警告的HTTP请求的映射导致的CSS问题,spring,spring-mvc,Spring,Spring Mvc,每当我向RequestMapping路径添加任何内容时,我都会遇到解析CSS文件路径的问题。在下面的示例中,如果我更改 @RequestMapping(value=“/articles/view”,method=RequestMethod.GET) 到 @RequestMapping(value=“/articles”,method=RequestMethod.GET) 它很好用。如果我尝试使用路径变量,映射css文件时也会遇到问题。我的css文件位于名为/data/css的文件夹中,其中/da

每当我向RequestMapping路径添加任何内容时,我都会遇到解析CSS文件路径的问题。在下面的示例中,如果我更改

@RequestMapping(value=“/articles/view”,method=RequestMethod.GET)

@RequestMapping(value=“/articles”,method=RequestMethod.GET)

它很好用。如果我尝试使用路径变量,映射css文件时也会遇到问题。我的css文件位于名为/data/css的文件夹中,其中/data与我的/WEB-INF处于同一级别

ArticlesAction.java:

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

@Controller
public class ArticlesAction {

    @RequestMapping(value="/articles/view", method = RequestMethod.GET)
    public String printWelcome(ModelMap model) {

        //model.addAttribute("id", id);
        return "articles";

    }
}
web.xml

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

    <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
</web-app>

mvc调度器
org.springframework.web.servlet.DispatcherServlet
1.
mvc调度器
/
上下文配置位置
/WEB-INF/mvc-dispatcher-servlet.xml
org.springframework.web.context.ContextLoaderListener
index.html
mvc-dispatcher-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans     
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/mvc  
        http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd 
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">


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

    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/pages/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>
</beans>

/WEB-INF/pages/
.jsp
articles.jsp

<!DOCTYPE html>
<html class="no-js" lang="en-US">

    <!-- Head section -->
    <head>

        <meta charset="utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
        <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
        <meta name="description" content="Responsive website template by kubasto" />
        <meta name="msapplication-TileImage" content="data/img/tile/w.png" />
        <meta name="msapplication-TileColor" content="#089bc3" />

        <link rel="shortcut icon" href="data/img/favicon/w.png" />
        <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Rokkitt:400,700" />
        <link rel="stylesheet" href="data/css/fancybox.css" />
        <link rel="stylesheet" href="data/css/flexslider.css" />
        <link rel="stylesheet" href="data/css/mejs.css" />
        <link rel="stylesheet" href="data/css/tipsy.css" />
        <link rel="stylesheet" href="data/css/base.css" />
        <link rel="stylesheet" href="data/css/structure.css" />
        <link rel="stylesheet" href="data/css/parts.css" />
        <link rel="stylesheet" href="data/css/widgets.css" />
        <link rel="stylesheet" href="data/css/bright.css" />
        <link rel="stylesheet" href="data/css/color.css" />

尝试使用特殊的mvc:resources标记:

<mvc:resources location="/, classpath:/META-INF/web-resources/" mapping="/resources/**"/>

要使用它,请将“mvc”命名空间添加到您的mvc dispatcher servlet.xml

中,并添加到mvc-dispatcher-servlet.xml中。并确保您有适当的资源路径
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans     
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/mvc  
        http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd 
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">


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

    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/pages/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>
</beans>