Announcement Announcement Module
Collapse
No announcement yet.
No mapping found Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • No mapping found

    Hi,

    I'm using Spring 3.1.0 M2 version to try to makework as expected (i.e. using /WEB-INF/views/home.jsp to render the response) but got the same error below:
    Code:
    org.springframework.web.servlet.DispatcherServlet noHandlerFound
    WARNING: No mapping found for HTTP request with URI [/spring/WEB-INF/views/home.jsp] in DispatcherServlet with name...
    Please note that spring is the context.

    web.xml is:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    
    	<servlet>
    		<servlet-name>Spring MVC Dispatcher Servlet</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>Spring MVC Dispatcher Servlet</servlet-name>
    		<url-pattern>/*</url-pattern>
    	</servlet-mapping>
    	
    </web-app>
    spring-config.xml is:
    Code:
    <?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:context="http://www.springframework.org/schema/context"
    	xmlns:mvc="http://www.springframework.org/schema/mvc"
    	xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    
    	<context:component-scan base-package="com.hi"/>
    
    	<mvc:annotation-driven/>
    
    	<mvc:view-controller path="/" view-name="home"/>
    
    	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    		<property name="prefix" value="/WEB-INF/views/"/>
    		<property name="suffix" value=".jsp"/>
    	</bean>
    
    </beans>
    HomeController.java is below:
    Code:
    package com.hi;
    ...
    @Controller
    @RequestMapping("/home")
    public class HomeController {
    	
    	@RequestMapping(method=RequestMethod.GET)
    	public String getHomePage() {
    		return "home";
    	}
    	
    }
    home.jsp is located under WEB-INF/views/ folder.

    Can anyone point me where I'm doing wrong?

    Thanks a lot!
    Last edited by ee722; Sep 25th, 2011, 11:27 AM. Reason: Added "spring" is the context.

  • #2
    The problem is that you are mapping / to home... That isn't going to work, you get into a loop. (ie. remove the view-controller and let that resolve to the default handler).

    Comment


    • #3
      Hi Marten,

      Thanks for your reply.

      Originally posted by Marten Deinum View Post
      The problem is that you are mapping / to home... That isn't going to work, you get into a loop. (ie. remove the view-controller and let that resolve to the default handler).
      After <mvc:view-controller.../> is commented out, it still doesn't work. The details are below:

      http://localhost:8080/spring causes this error:
      Code:
      org.springframework.web.servlet.DispatcherServlet noHandlerFound
      WARNING: No mapping found for HTTP request with URI [/spring] in DispatcherServlet with name 'Spring MVC Dispatcher Servlet'

      http://localhost:8080/spring/ causes this error:
      Code:
      org.springframework.web.servlet.DispatcherServlet noHandlerFound
      WARNING: No mapping found for HTTP request with URI [/spring/] in DispatcherServlet with name 'Spring MVC Dispatcher Servlet'

      http://localhost:8080/spring/home causes this error:
      Code:
      org.springframework.web.servlet.DispatcherServlet noHandlerFound
      WARNING: No mapping found for HTTP request with URI [/spring/WEB-INF/views/home.jsp] in DispatcherServlet with name 'Spring MVC Dispatcher Servlet'
      The errors in the first two cases make sense because url pattern "" and "/" are not set up. Why does the 3rd case also cause an error?

      Thanks.
      Last edited by ee722; Sep 25th, 2011, 04:30 PM.

      Comment


      • #4
        The first 2 are correct, that is what I would have expected. The third isn't that would only happen if it couldn't find home.jsp in your WEB-INF/views directory, so you might want to check if it is there and that it can be resolved. There should be more information in the log (you might want to enable debug logging to see what is happening).

        Comment


        • #5
          ee722, did you ever resolve this? I am having the same issue.

          Originally posted by Marten Deinum View Post
          The third isn't that would only happen if it couldn't find home.jsp in your WEB-INF/views directory, so you might want to check if it is there and that it can be resolved. There should be more information in the log (you might want to enable debug logging to see what is happening).
          I don't think so. Note that the error is not on /WEB-INF/views/home.jsp, but rather /[context]/WEB-INF/views/home.jsp (context being "spring" in this case). For some reason the context path is getting inserted, even though the view resolver prefix begins with /WEB-INF/.

          Comment


          • #6
            @ee72

            What will happen if you access -> http://localhost:8080/home

            Comment


            • #7
              Originally posted by lukpac

              I don't think so. Note that the error is not on /WEB-INF/views/home.jsp, but rather /[context]/WEB-INF/views/home.jsp (context being "spring" in this case). For some reason the context path is getting inserted, even though the view resolver prefix begins with /WEB-INF/.
              Trust me it is...

              If there is no view the request is being handled as a normal request by the DispatcherServlet, the exception is about a mapping from the dispatcherservlet if the view would resolve correctly this wouldn't happen (view rendering is handled internally to the DispatcherServlet).

              Comment


              • #8
                Originally posted by Marten Deinum View Post
                Trust me it is...

                If there is no view the request is being handled as a normal request by the DispatcherServlet, the exception is about a mapping from the dispatcherservlet if the view would resolve correctly this wouldn't happen (view rendering is handled internally to the DispatcherServlet).
                Trust you it is what?

                Look at the mapping again:

                Code:
                	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                		<property name="prefix" value="/WEB-INF/views/"/>
                		<property name="suffix" value=".jsp"/>
                	</bean>
                The mapping for "home" is correctly using "/WEB-INF/views/" and ".jsp" for the prefix and suffix. However, /spring (the web app context) is getting inserted ahead for the prefix for some reason, causing an error. That is:

                /WEB-INF/views/home.jsp

                Exists. However:

                /spring/WEB-INF/views/home.jsp is an invalid path.

                Why is the context getting inserted into the JSP lookup? If it wasn't, the mapping would work.

                Comment


                • #9
                  Your logic is wrong as I tried to explain...

                  The view at /WEB-INF/views/home.jsp isn't found and hence a new request is being issued as it is then assumed it is a request to a new URL. This is also why you get the mapping exception as this new request is then handled by the DispatcherServlet.

                  /spring (the web app context) is getting inserted ahead for the prefix for some reason, causing an error
                  See above... It is not getting inserted it is the result of the new request and the reques is the result of a non existing/readable file.

                  Comment


                  • #10
                    Originally posted by Marten Deinum View Post
                    Your logic is wrong as I tried to explain...

                    The view at /WEB-INF/views/home.jsp isn't found and hence a new request is being issued as it is then assumed it is a request to a new URL. This is also why you get the mapping exception as this new request is then handled by the DispatcherServlet.
                    Why isn't the view found? The file /WEB-INF/views/home.jsp exists.

                    For the heck of it, I tried changing my context root to /. Oddly, it still doesn't work:

                    Code:
                    org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/WEB-INF/jsp/index.jsp] in DispatcherServlet with name 'spring-sort-mvc'
                    However, /WEB-INF/jsp/index.jsp definitely exists.

                    Comment


                    • #11
                      FYI, changing the url-pattern in servlet-mapping from /* to / seems to have resolved the issue. I had to work around a number of other things (in particular static content), but I think things are working now.

                      Comment


                      • #12
                        Why isn't the view found?
                        Well if you can answer that question you wouldn't have this problem would you... (Could be your servlet mapping sometimes odd things happen when you map to /* or / depending on your container).

                        However, /WEB-INF/jsp/index.jsp definitely exists.
                        I thought it was views instead of jsp for the directory?!

                        Comment


                        • #13
                          Originally posted by Marten Deinum View Post
                          Well if you can answer that question you wouldn't have this problem would you... (Could be your servlet mapping sometimes odd things happen when you map to /* or / depending on your container).
                          See above. Switching to / worked, although 1) I'm not entirely sure why and 2) I ran into some other issues that I had to deal with because of that, which initially threw me off.

                          Originally posted by Marten Deinum View Post
                          I thought it was views instead of jsp for the directory?!
                          It was for the OP. But in my app it is /WEB-INF/jsp/.

                          Comment


                          • #14
                            mapping to / replaces the standard servlet mapping (assuming you use tomcat the tomcat default servlet) which is why things like serving static resources stop working (you can use the mvc:default-servlet-handler to enable that again or explicitly use the mvc:resources tag to serve resources).

                            Comment


                            • #15
                              Originally posted by Marten Deinum View Post
                              mapping to / replaces the standard servlet mapping (assuming you use tomcat the tomcat default servlet) which is why things like serving static resources stop working (you can use the mvc:default-servlet-handler to enable that again or explicitly use the mvc:resources tag to serve resources).
                              mvc:resources (and some mappings for my interceptors so they wouldn't be invoked for static content) worked, although as previously stated, the difference between / and /* for the servlet mapping is still a bit confusing.

                              Setting the servlet mapping so everything is under a sub path would make things easier (i.e., /app/*), which is how my application (which I inherited) was originally setup, but there was some URL rewriting going on that made things problematic and confusing. Behind the scenes /app was used, but the rewriting was hiding that from users. A side effect of all of this was the application wouldn't work under any context path except /. That's all mostly resolved now but there are still a few issues to work through.

                              Comment

                              Working...
                              X