springmvc 請求無法到達controller,出現404


今天在配置SpringMVC時,訪問項目一直出現404,無法訪問。

報錯:

The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

調試了一下,發現沒有到達controller層里面。

運行后沒有到達controller層的解決方法:

1.檢查web.xml文件中的SpringMVC的配置是否正確。

  <!-- Spring MVC servlet -->
    <servlet>
        <servlet-name>SpringMVC</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <!--<init-param>表示啟動時初始化的配置文件-->
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring-mvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
        <async-supported>true</async-supported>
    </servlet>
    <servlet-mapping>
        <!--<servlet-mapping>中的</servlet-name>必須與<servlet>里面的<servlet-name>保持一致-->
        <servlet-name>SpringMVC</servlet-name>
        <!-- 一般定義為 / ,表示所有請求都通過DispatcherServlet來處理-->
        <url-pattern>/</url-pattern>
    </servlet-mapping>

2.檢查spring-mvc.xml,是否添加了注解驅動

    <!--注解驅動-->
    <mvc:annotation-driven/>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM