2015-11-04 66 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