Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Spring MVC: No mapping found for HTTP request with URI

I've problems setting up Spring MVC... I've this project structure

-SpringTest<br />
   -Java Resources
      -src
         -org.basic.controller
             FormController.java
.
.
.
.
-WebContent
   +META-INF
   -WEB-INF
       dispatcher-servlet.xml
       +lib
       -views
           form.jsp
       web.xml

And these are the code pages:

web.xml

<web-app id="WebApp_ID" version="2.4" 
    xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

  <display-name>Spring Web MVC Application</display-name>

  <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>

</web-app>

dispatcher-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
    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-2.5.xsd">



    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
        <property name="prefix">
            <value>/WEB-INF/views/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>

</beans>

FormController.java

package org.basic.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/form.html")
public class FormController {


}

But when, after a deploy with jboss, I try to access "/SpringTest/form.htm" it gives back this error:

WARN [org.springframework.web.servlet.PageNotFound] (http-localhost-127.0.0.1-8080-1) No mapping found for HTTP request with URI [/SpringTest/form.htm] in DispatcherServlet with name 'dispatcher'

like image 280
Andrea Dorigo Avatar asked Nov 18 '25 16:11

Andrea Dorigo


1 Answers

@RequestMapping("/form.html")

vs

/SpringTest/form.htm

You have an extra l in your @RequestMapping url.

Don't forget to component-scan the package your controller is in.

like image 171
Sotirios Delimanolis Avatar answered Nov 20 '25 08:11

Sotirios Delimanolis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!