Search code examples
javaspringspring-mvcweb.xml

No mapping found for Index.html


Consider the following Controller

@Controller
public class HomeController {

@RequestMapping(value="/")
public ModelAndView home() {
    ModelAndView model = new ModelAndView("index");
    return model;
}

And this s my servlet-context.xml:

<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/views/" />
    <property name="suffix" value=".html" />
</bean>

And this is my web.xml:

<!-- Processes application requests -->
<servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

Every time I hit the url I get this message:

Aug 08, 2015 10:59:47 PM org.springframework.web.servlet.PageNotFound noHandlerFound WARNING: No mapping found for HTTP request with URI [/MeraComputer/WEB-INF/views/index.html] in DispatcherServlet with name 'appServlet' Aug 08, 2015 10:59:48 PM org.springframework.web.servlet.PageNotFound noHandlerFound WARNING: No mapping found for HTTP request with URI [/MeraComputer/WEB-INF/views/index.html] in DispatcherServlet with name 'appServlet'

My folder structure is also good,I suppose,

Folder Structure


Solution

  • I think static html files won't work as views. The request is being forwarded to the view, i.e. to /MeraComputer/WEB-INF/views/index.html, and because it's a static file but not a request handler, you may be getting the warning.

    Static files should be handled differently. This is a similar post, I think, which could help.