Results 1 to 8 of 8

Thread: No mapping found for HTTP request with URI in Spring MVC 3

  1. #1

    Question No mapping found for HTTP request with URI in Spring MVC 3

    Even though I've mapped a controller to handle a URI, I get: No mapping found for HTTP request with URI [/login]. Below are my dispatcher servlet configuration and the controller class; anyone see what is causing the error?

    Code:
    <servlet>
      	<servlet-name>dispatcher-servlet</servlet-name>
      	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
      	<load-on-startup>1</load-on-startup>
      </servlet>
    
    <servlet-mapping>
      	<servlet-name>dispatcher-servlet</servlet-name>
      	<url-pattern>/</url-pattern>
      </servlet-mapping>
    Code:
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.servlet.ModelAndView;
    
    @Controller
    @RequestMapping("/login")
    public class LoginController {
    	
    	@RequestMapping(value="/")
    	public String loginView() {
    		return "login";
    	}
    	
    	@RequestMapping(value="/{error}") 
    	public ModelAndView loginErrorView(@PathVariable("error") String error) {
    		ModelAndView mav = new ModelAndView();
    		mav.setViewName("login");
    		mav.addObject("error", error);
    		return mav; 
    	}
    }

  2. #2

    Default URL Pattern on Servlet Mapping

    Change your URL pattern on your servlet mapping from "/" to "/*" (without the double quotes) and that should fix the issue.

  3. #3

    Default

    Quote Originally Posted by jmoore_aus View Post
    Change your URL pattern on your servlet mapping from "/" to "/*" (without the double quotes) and that should fix the issue.
    Thanks for the suggestion. I tried it, but unfortunately, it does not resolve the issue; I continue to get:

    Jun 2, 2010 3:51:35 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
    WARNING: No mapping found for HTTP request with URI [/login] in DispatcherServlet with name 'dispatcher-servlet'
    Any other ideas?

  4. #4

    Default

    Quote Originally Posted by dan0 View Post
    Any other ideas?
    The next step is to make sure your configuration is using annotation driven configuration / scanning.

    Post your configuration files.

  5. #5

    Default

    Quote Originally Posted by jmoore_aus View Post
    Post your configuration files.
    *-servlet.xml file:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:context="http://www.springframework.org/schema/context"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:mvc="http://www.springframework.org/schema/mvc"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="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
           http://www.springframework.org/schema/mvc
           http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    
        <context:component-scan base-package="com.utility.web.controllers" />
        <context:annotation-config />
        <mvc:annotation-driven />
        
    	<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    		<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
    		<property name="prefix" value="/WEB-INF/jsp/"/>
    		<property name="suffix" value=".jsp"/>
    	</bean>
    	
    	<mvc:view-controller path="/" view-name="index"/>
    	<!-- <mvc:view-controller path="/login" view-name="login"/> -->
    	<!-- <mvc:view-controller path="/login/error" view-name="login"/> -->
        
    </beans>
    *Note: if I use the mvc:view-controller tag for "/login", the proper jsp is displayed.

  6. #6

    Default

    Just out of curiosity what happens if you add this guy in there?

    <bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotat ion.DefaultAnnotationHandlerMapping">
    <property name="order" value="1" />
    </bean>

  7. #7

    Default

    Quote Originally Posted by jmoore_aus View Post
    Just out of curiosity what happens if you add this guy in there?

    <bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotat ion.DefaultAnnotationHandlerMapping">
    <property name="order" value="1" />
    </bean>
    I get the same error message:

    Jun 2, 2010 4:14:46 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
    WARNING: No mapping found for HTTP request with URI [/login] in DispatcherServlet with name 'dispatcher-servlet'

  8. #8

    Default

    replace your code in web.xml file with this:

    <servlet>
    <servlet-name>dispatcher-servlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>

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

    if it not works, try to use the controllerclassnamehandlermapping with out changing above code given by me in web.xml
    Last edited by raja_jan09; Jun 3rd, 2010 at 08:06 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •