0

http status 404 is thrown while accessing the url localhost:8080/todolistapp/index.html

2014-11-08 01:09:58 WARN  PageNotFound:1114 - No mapping found for HTTP request with URI [/todolistapp/index.html] in DispatcherServlet with name 'mvc-dispatcher'

This is my web.xml

<servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

A Spring REST application, which has html files, accessing to REST API in the same project

@Controller
@RequestMapping("/todo")
public class TaskController {
   .................
}

I can access the url like

http://localhost:8080/todolistapp/todo/list
http://localhost:8080/todolistapp/todo/delete/2

but when i try to access the index.html it throws the error

enter image description here

WARN  PageNotFound:1114 - No mapping found for HTTP request with URI [/todolistapp/index.html] in DispatcherServlet with name 'mvc-dispatcher'

This is my Project Layout

enter image description here

anish
  • 6,884
  • 13
  • 74
  • 140

3 Answers3

0

in your web.xml change

<servlet-mapping>
   <servlet-name>mvc-dispatcher</servlet-name>
   <url-pattern>/*</url-pattern>
</servlet-mapping>

to

<servlet-mapping>
   <servlet-name>mvc-dispatcher</servlet-name>
   <url-pattern>/</url-pattern>
</servlet-mapping>
Prasad Khode
  • 6,602
  • 11
  • 44
  • 59
0

in my web.xml I have:

<servlet-mapping>
    <servlet-name>restServices</servlet-name>
    <url-pattern>/rest/*</url-pattern>
    <url-pattern>/rest</url-pattern>
</servlet-mapping>

which helps with some pattern matching (you of course might omit the "/rest" bit and have:

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

I'm noticing that your @RequestMapping is for "/todo", yet your access seems to be "/todolistapp".

Finally, if your up to drinking from a firehose, you could set logging to DEBUG for context: "org.springframework.web.servlet.mvc"

BrianT.
  • 394
  • 1
  • 6
0

As other noted, mapping a DispatcherServlet to /* and to / is not same thing. When you map it to /* is takes absolutely all URLs and you have to tell Spring MVC what URL it must considere as static resources to serve them directly instead of looking for Spring controllers.

At the opposite when you map it to /, it comes with a last priority.

It also changes the way the root URL is processed.

You will find more detailed explaination and references on this related post

Community
  • 1
  • 1
Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252