2016-05-16 59 views
1

[/運動漫畫/首頁/]我有問題frameowrk.org.springframework.web.servlet.DispatcherServlet保持獲得狀態404警告:spring3未找到HTTP請求的URI與映射的DispatcherServlet

文件名是WelcomeController.java

package com.rethink.controller; 

import java.util.Map; 

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

@Controller 
@RequestMapping("/welcome") 
public class WelcomeController { 

    @RequestMapping(method = RequestMethod.GET) 
    public String displayMessage(Map<String, String> map){ 
      System.out.println("In"); 
     map.put("loginmessage","Please Login with Your Details");  
     return "index"; 
    } 

} 

這是我的web.xml和運動漫畫-servlet.xml中

Click here for web.xml and motion-comics-servlet.xml screen shot

我已經把我的觀點在Web頁/ WEB-INF/JSP/index.jsp的

不管我怎麼努力,我只是不能讓它工作....

我的幫助和諮詢會不勝感激....

在此先感謝

+0

在servlet映射的web.xml中的URL模式中嘗試/ **(slashStarStar) –

+0

@lamba對不起,這不起作用 – Ahmed

+0

@Ahmed你想說你已經保持你的index.jsp文件的位置 - WebContent/Web-INF/jsp/index.jsp? – asg

回答

0

我嘗試了一些例子,發現夫婦的配置更改在你的代碼是必需的。

  1. 將<添加到您的motion-comics-servlet.xml文件的mvc:annotation-driven />。
<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"> 

     <!-- Add this to your xml file --> 
     <mvc:annotation-driven/> 

     <!-- Make sure that you are scanning all your packages required for your application --> 
     <context:component-scan base-package="com.rethink.controller"></context:component-scan>  


     <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" 

       <property name="prefix"> 
        <value>/WEB-INF/jsp/</value> 
       </property> 
       <property name="suffix"> 
       <value>.jsp</value> 
       </property> 
     </bean> 

</beans> 
  • 變化運動漫畫Servlet映射到下面的配置。改成 '/'。去掉 *。

    <servlet-mapping> 
        <servlet-name>motion-comcis</servlet-name> 
        <url-pattern>/</url-pattern> 
    </servlet-mapping> 
    
  • 請讓我知道如果你遇到任何問題。

    0

    可以驗證Spring Web MVC框架日誌,控制器是否得到註冊該URL或沒有。同時驗證組件掃描是否正確設置。

    此外,您可以驗證視圖解析器是否被適當地配置。

    爲了更詳細的瞭解check this post

    +0

    感謝輸入的人,但即使添加後,這不起作用....但是, mvc:註解驅動>我怎麼能添加這個?任何幫助將很多appriciated – Ahmed

    +0

    你需要將其添加到applicationContext.xml中。請參閱http://docs.spring.io/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-config – Chaitu

    +0

    上的spring文檔。添加了但開始收到此錯誤:匹配的通配符是嚴格的,但沒有聲明可以找到元素'mvc:annotation-driven'。 – Ahmed

    相關問題