2013-08-16 48 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

相關問題