2015-11-04 63 views
0

結構:Spring MVC的頁面是不加入MVC後訪問:資源

Structure

MVC-調度-servlet.xml中:

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

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

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

<mvc:resources mapping="/resources/**" location="/resources/" /> 

控制器:

@Controller 
public class MainController { 
    @RequestMapping(value = {"/", "/home"}, method = RequestMethod.GET) 
    public String printWelcome(ModelMap model) { 
     model.addAttribute("message", "Hello world!"); 
     return "hello"; 
    } 
} 

加入MVC後:資源標記我進入我的資產(這裏是一切正常,因爲它應該是): Everything is fine

但在那之後,如果我試圖訪問我的主頁,這是不工作了: Homepage is not working

問題出在哪裏?

在此先感謝。

回答

1

我認爲你正在使用彈簧3,您需要添加

<mvc:annotation-driven> 

運行

<mvc:resources> 

你可以試試這個?

+0

是的,我已經試過了。遊戲/主頁正在工作,但如果我嘗試遊戲/(我的索引頁面)它說:模糊處理程序方法映射爲HTTP路徑'http:// localhost:8080/game /':{public java.lang.String com.javaguru .game.HelloController.printWelcome(org.springframework.ui.ModelMap),public java.lang.String com.javaguru.game.MainController.printWelcome(org.springframework.ui.ModelMap)} – Aleksandrs

+0

但是,當我看到你的異常,我看到有兩個不同的控制器,你好,主控制器。在HelloContoller中是否有任何方法指向/ game /的路徑?這會導致模糊。 –

+0

我更新了結構圖。我只有一個控制器。 – Aleksandrs