4

My dispatcher-servlet.xml

   <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
        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-3.0.xsd">
        <mvc:annotation-driven/>
        <context:component-scan base-package="com.example" />

    <bean id="viewResolver"
                class="org.springframework.web.servlet.view.InternalResourceViewResolver"
                p:prefix="/WEB-INF/views/" p:suffix=".jsp" p:viewClass="org.springframework.web.servlet.view.JstlView"/>  

</beans>

And this is my controller

package com.example.spring;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class HelloController {

        @RequestMapping("/form.htm")
        public ModelAndView hello(Model model) {
                return new ModelAndView("index");
        }
}

I see this in my console when I have the app in debug.

WARNING: No mapping found for HTTP request with URI [/WEB-INF/views/index.jsp] in DispatcherServlet with name 'dispatcher'

The controller gets hit, and returns the view, but then it can't be resolved.

stevebot
  • 23,275
  • 29
  • 119
  • 181
  • can you post your dispatcher servlet's mapping conf from web.xml – jmj Mar 09 '11 at 06:05
  • 2
    Have a look at this question: http://stackoverflow.com/questions/1266303/no-mapping-found-for-http-request-with-uri-web-inf-pages-apiform-jsp – Javi Mar 09 '11 at 08:58
  • Can you post project's structure and also your web.xml? – chris Mar 09 '11 at 10:32
  • @Javi: related, but my servlet config is already set to map /*.htm to my dispatcher servlet, not /* – stevebot Mar 09 '11 at 15:48

2 Answers2

3

Sounds like you might be missing the following in your web.xml

<servlet>
    <servlet-name>jsp</servlet-name>
    <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>jsp</servlet-name>
    <url-pattern>/WEB-INF/views/*</url-pattern>
</servlet-mapping>

As @Javi already commented, this is already answered here.

Community
  • 1
  • 1
andyb
  • 43,435
  • 12
  • 121
  • 150
  • I couldn't infer this from Spring's documentation. Do you have a reference? – stevebot Mar 09 '11 at 15:49
  • 2
    I am not sure what your web.xml looks like but assume that you have a url-pattern of `/` being mapped to the DispatcherServlet. There is a [previous answer](http://stackoverflow.com/questions/234210/can-anyone-explain-servlet-mapping/245143#245143) that explains the servlet-mapping. Basically I think that the JSP is being routed through the DispatcherServlet since there is no explicit mapping. The above code adds that mapping which routes everything under `/WEB-INF/views/` to the `JspServlet`. I think I got the original information [here](http://anders.com/projects/sysadmin/tomcat.html) – andyb Mar 09 '11 at 16:10
1

Add an index.jsp to your /WEB-INF/views/ directory.

sdavids
  • 1,527
  • 9
  • 11
  • @stevebot - all seems fine, make sure the file is deployed to the server, and is not only in your dev env. – Bozho Mar 09 '11 at 09:12