2013-08-16 50 views
0

我有问题解决我的CSS文件的路径,每当我添加任何东西到我的RequestMapping路径。在下面的例子中,如果我改变来自没有找到HTTP请求与URI警告映射的CSS问题

@RequestMapping(值= “/物品/视图”,方法= RequestMethod.GET)

@RequestMapping(值= “/ 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-调度-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> 

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" /> 

回答

0

尝试使用特殊的MVC:资源标签:

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

要使用它添加“MVC”命名空间到你的MVC-调度-servlet.xml中

+0

没有我得到的所有的404错误我网址。 – user2664559

+0

添加到mvc-dispatcher-servlet.xml中。并确保你有适合你的资源的路径 – yname

相关问题