2014-03-01 23 views
0

我現在面臨很常見的問題而設立的Spring MVC +磚項目部署在Spring MVC,並與無映射瓷磚未能找到與URI

我得到HTTP請求「無映射發現與URI HTTP請求[//home.htm在DispatcherServlet的名稱爲

我的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" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
    id="WebApp_ID" 
    version="3.0" 
> 
    <servlet> 
     <servlet-name><PROJECT_NAME></servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet 
     </servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name><PROJECT_NAME></servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 
    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 
    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/<PROJECT_NAME>-servlet.xml</param-value> 
    </context-param> 
    <welcome-file-list> 
     <welcome-file>  
      home.htm  
     </welcome-file> 
    </welcome-file-list> 
</web-app> 

我的瓷磚XML是

<!DOCTYPE tiles-definitions PUBLIC 
     "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN" "http://tiles.apache.org/dtds/tiles-config_2_0.dtd"> 
<tiles-definitions> 
<definition name="baseLayout" template="/WEB-INF/jsp/layout.jsp"> 
    <put-attribute name="title" value="Sample Title" /> 
    <put-attribute name="header" value="/WEB-INF/jsp/header.jsp" /> 
    <put-attribute name="menu" value="/WEB-INF/jsp/menu.jsp" /> 
    <put-attribute name="body" value="" /> 
    <put-attribute name="footer" value="/WEB-INF/jsp/footer.jsp" /> 
</definition> 

<definition name="home" extends="baseLayout"> 
    <put-attribute name="title" value="Home" /> 
    <put-attribute name="body" value="/WEB-INF/jsp/home.jsp" /> 
</definition> 

    <definition name="page" extends="baseLayout"> 
    <put-attribute name="title" value="Page" /> 
    <put-attribute name="body" value="/WEB-INF/jsp/page.jsp" /> 
</definition> 
</tiles-definitions> 

PROJECT_NAME-servlet.xml中是

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

    <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"> 
     <property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView" /> 
    </bean> 

    <bean 
     id="tilesConfigurer" 
     class="org.springframework.web.servlet.view.tiles3.TilesConfigurer" 
    > 
     <property name="definitions"> 
      <list> 
       <value>/WEB-INF/tiles.xml</value> 
      </list> 
     </property> 
    </bean> 
</beans> 

應用程序的context.xml是

<beans 
    xmlns="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    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/context 
     http://www.springframework.org/schema/context/spring-context-3.0.xsd 
     http://www.springframework.org/schema/mvc 
     http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd" 
> 
    <context:component-scan base-package="com.project" /> 
    <context:annotation-config /> 

    <mvc:annotation-driven /> 

    <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/> 
    <bean class="org.springframework.web.context.request.async.StandardServletAsyncWebRequest"/> 
</beans> 

homecontroller.java是

package com.project.controller; 

import javax.servlet.http.HttpServletRequest; 

import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestParam; 

@Controller  
public class HomeController {  


    @RequestMapping("/home.htm")  
    public String myhome() {  
     System.out.println("INSIDE MY HOME"); 
     return "home";  
    }  

    @RequestMapping("/page.htm")  
    public String page(@RequestParam(value="pageNo") String pageNo,HttpServletRequest request) { 
     System.out.println("PageNo: " + pageNo); 
     request.setAttribute("pageNo", pageNo); 
     return "page";  
    }  
} 

我發現很多的互聯網解決方案,但沒有工作。我試過以下東西:

  1. 檢查服務器部署目錄也一切都正常部署。
  2. 在web.xml,在的servlet URL模式,我試圖/,/ 的.htm
  3. 在控制器中,請求映射我試圖/home.htm,/project_name/home.htm,/
  4. 我已經嘗試在application-context.xml中爲不同的spring類使用bean。

但沒有任何工作。

我爲擊球http://localhost:8080/PROJECT-NAME/home.htm

+0

檢查您的日誌(至少在信息級別),哪些請求映射已註冊? –

+0

如何檢查哪些請求映射已註冊? ...我註冊的網絡上下文是/ project_number。除了許多其他與服務器相關的日誌在那裏沒有任何異常 – user1653773

+0

應該有一個'RequestMappingHandlerMapping'類的消息'Mapped .. [註冊處理程序]'的日誌消息。 –

回答

1

在您的應用程序上下文文件擺脫這種

<mvc:annotation-driven /> 

<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/> 
<bean class="org.springframework.web.context.request.async.StandardServletAsyncWebRequest"/> 

,並把它們放到你的servlet上下文的文件與相應的組件掃描。


在一種相關說明中,請勿使用DefaultAnnotationHandlerMappingmvc:annotation-driven已經註冊了合適的HandlerMappingRequestMappingHandlerMapping

+0

謝謝,我的問題解決了......我剛剛刪除了這兩個bean,並將該組件掃描部分移到了servlet上下文文件中。 – user1653773

+0

@ user1653773不客氣。 –