HTTP Status 404 on Spring 3.1 MVC app

后端 未结 1 804
[愿得一人]
[愿得一人] 2021-01-15 16:31

i am trying to create and run a simple Spring 3.1 mvc web application where i have defined a controller that simply returns \"hello\" in the response body using the class be

相关标签:
1条回答
  • 2021-01-15 16:43

    Your DispatcherServlet is mapped to *.htm:

    <servlet-mapping>
        <servlet-name>FreedomSpring</servlet-name>
        <url-pattern>*.htm</url-pattern>
    </servlet-mapping>
    

    But you are accessing the controller through non-matching URL: http://localhost:8080/FreedomSpring/hello. You have three choices:

    1. Change you dispatcher servlet to:

      <servlet-mapping>
          <servlet-name>FreedomSpring</servlet-name>
          <url-pattern>/*</url-pattern>
      </servlet-mapping>
      

      but in this case all requests will be handled through the Spring MVC, including images and other static resources

    2. Use extension in controllers as well:

      <url-pattern>/*.htm</url-pattern>
      

      and map Hello controller to .htm so that you use: http://localhost:8080/FreedomSpring/hello.htm.

    3. Map controllers to a different subdirectory:

      <url-pattern>/mvc/*</url-pattern>
      

      to access them you will have to use: http://localhost:8080/FreedomSpring/mvc/hello without making any changes to the controller itself.

    0 讨论(0)
提交回复
热议问题