Announcement Announcement Module
Collapse
No announcement yet.
No mapping found for HTTP request with URI [/DAG_ERP/login.htm] in DispatcherServlet Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • No mapping found for HTTP request with URI [/DAG_ERP/login.htm] in DispatcherServlet

    Hi,

    I am developing one spring MVC web application in Spring 3.0. I've setup all environment for development in netbeans ide 7.2. When I am running the project it shows me warning on tomcat log file i.e. "No mapping found for HTTP request with URI [/DAG_ERP/login.htm] in DispatcherServlet with name 'dispatcher'" and on browser the link is broken message.

    web.xml file :
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="3.0" 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_3_0.xsd">    
        <servlet>
            <servlet-name>dispatcher</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-name>
            <url-pattern>*.htm</url-pattern>
        </servlet-mapping>     
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/applicationContext.xml</param-value>
        </context-param>
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>        
        <listener>
            <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
        </listener>
        <context-param>
            <param-name>log4jConfigLocation</param-name>
            <param-value>/WEB-INF/log4j.properties</param-value>
        </context-param>    
        <!-- Configuration to allow more than one application run in the same container(Tomacat Specific) -->
        <context-param>
            <param-name>log4jExposeWebAppRoot</param-name>
            <param-value>false</param-value>
        </context-param>    
        <session-config>
            <session-timeout>
                30
            </session-timeout>
        </session-config>
        <welcome-file-list>
            <welcome-file>redirect.jsp</welcome-file>
        </welcome-file-list>
        <error-page>
            <error-code>404</error-code>
            <location>/jsp/error/error.jsp</location>
        </error-page>    
        <error-page>
            <error-code>401</error-code>
            <location>/jsp/redirect.jsp</location>
        </error-page>
    </web-app>
    applicationContext.xml:

    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:p="http://www.springframework.org/schema/p"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xmlns:mvc="http://www.springframework.org/schema/mvc"
           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/tx
    			http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    			http://www.springframework.org/schema/mvc
    			http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    
        <!--bean id="propertyConfigurer"
              class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
              p:location="/WEB-INF/jdbc.properties" />
    
    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource"
        p:driverClassName="${jdbc.driverClassName}"
        p:url="${jdbc.url}"
        p:username="${jdbc.username}"
        p:password="${jdbc.password}" /-->
    
        <!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) -->
        <!--if no controller logic is required, mvc:view-controller can be used to simply show a view for a request  -->
        <mvc:view-controller path="/" view-name="redirect"/>
    
    <!--Enables many annotations and searches for @Controller annotated methods etc.. -->
        <context:annotation-config/>
    
        <context:component-scan base-package="com.dag.dag_erp"/>
    
        <mvc:annotation-driven/>
    
        <context:property-placeholder location="WEB-INF/config.properties"/>
    
        <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
            <property name="basenames">
                <list>
                    <value>resources.LabelResources</value>
                    <value>resources.ErrorResources</value>
                </list>
            </property>
        </bean>    
        <tx:annotation-driven transaction-manager="transactionManager"/>
        <bean id="transactionManager"
              class="org.springframework.orm.hibernate3.HibernateTransactionManager"
              p:sessionFactory-ref="sessionFactory"/>
    
        <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
            <property name="dataSource" ref="dataSource"/>
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                    <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                </props>
            </property>
            <property name="packagesToScan" value="com.dag.dag_erp"/>
        </bean>
    
        <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
              p:driverClassName="${jdbc.driverClassName}"
              p:url="${jdbc.url}"
              p:username="${jdbc.username}"
              p:password="${jdbc.password}"/>
             
        <bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
            <property name="exceptionMappings">
                <props>
                    <prop key="com.dag.dag_erp.exception.DAGException">error/exception</prop>
                    <prop key="java.lang.Exception">error/exception</prop>
                    <prop key="java.lang.NumberFormatException">error/exception</prop>
                    <prop key="java.lang.NullPointerException">error/exception</prop>
                </props>
            </property>
        </bean> 
    
    </beans>
    dispatcher-servlet.xml:
    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:p="http://www.springframework.org/schema/p"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
    	   		http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
     
        <bean id="viewResolver"
              class="org.springframework.web.servlet.view.InternalResourceViewResolver"
              p:prefix="/WEB-INF/jsp/"
              p:suffix=".jsp" />
    
    </beans>
    The welcome file opens correctly.
    I embedd one line of code into that redirect.jsp

    Code:
    <jsp:forward page="login.htm" />
    Which should send the request to controller where I want to show login.jsp

    The controller code is:

    LoginController.java
    Code:
    @Controller
    public class LoginController {
    @RequestMapping("/login")
        public ModelAndView showLoginForm() {
    	    LOGGER.info("requesting to login...");
            ModelAndView mav = new ModelAndView("login");       
            return mav;
        }
    Can anyone suggest me what is wrong with this code.
    Please any help appreciated.

    Thanks, Manveer

  • #2
    Your mapping is wrong... Your dispatcher servlet looks at *.htm mappings and your controller listens at /login not login.htm so it will never match.

    Another note you have 2 instances of the ContextLoaderListener in your web.xml why? Remove one.

    Comment


    • #3
      Hi,

      Thank you for your support. The correct web.xml is:
      <?xml version="1.0" encoding="UTF-8"?>
      <web-app version="3.0" 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_3_0.xsd">
      <servlet>
      <servlet-name>dispatcher</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>*.htm</url-pattern>
      </servlet-mapping>
      <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/applicationContext.xml</param-value>
      </context-param>
      <listener>
      <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
      </listener>
      <listener>
      <listener-class>org.springframework.web.util.Log4jConfigList ener</listener-class>
      </listener>
      <context-param>
      <param-name>log4jConfigLocation</param-name>
      <param-value>/WEB-INF/log4j.properties</param-value>
      </context-param>
      <!-- Configuration to allow more than one application run in the same container(Tomacat Specific) -->
      <context-param>
      <param-name>log4jExposeWebAppRoot</param-name>
      <param-value>false</param-value>
      </context-param>
      <session-config>
      <session-timeout>
      30
      </session-timeout>
      </session-config>
      <welcome-file-list>
      <welcome-file>redirect.jsp</welcome-file>
      </welcome-file-list>
      <error-page>
      <error-code>404</error-code>
      <location>/jsp/error/error.jsp</location>
      </error-page>
      <error-page>
      <error-code>401</error-code>
      <location>/jsp/redirect.jsp</location>
      </error-page>
      </web-app>
      I searched and found that we can set url-pattern as it is. So I don't think that is wrong. I have one working example for the same
      <servlet-mapping>
      <servlet-name>dispatcher</servlet-name>
      <url-pattern>*.htm</url-pattern>
      </servlet-mapping>
      In redirect.jsp I use this code to send redirect directly to login.jsp

      <%response.sendRedirect("login.htm"); %>
      Please do let me know if there is something wrong. I am still not able to run my project. Any help would be greatly appreciated!


      Thanks, Manveer
      Last edited by manveer88; Oct 17th, 2012, 06:36 AM.

      Comment


      • #4
        Read...

        Your DispatcherServlet listens to *.htm so it reacts to /DAG_ERP/login.htm... But your controller is mapped to /DAG_ERP/login no match... (As I explained in the post earlier).

        So as stated your mapping is wrong either change your controller mapping or dispatcher servlet mapping and redirect to /login instead of /login.htm...

        And I stronglky suggest a read of the spring reference guide and servlet specification to get a feel for how things work.

        Comment

        Working...
        X