[spring] No mapping found for HTTP request with URI [/WEB-INF/pages/apiForm.jsp]

My handler forwards to internalresourceview 'apiForm' but then i get error 404 RequestURI=/WEB-INF/pages/apiForm.jsp. I'm sure apiForm.jsp located in /WEB-INF/pages/

13:45:02,034 DEBUG [org.springframework.web.servlet.view.JstlView] - Forwarding to resource [/WEB-INF/pages/apiForm.jsp] in InternalResourceView 'apiForm'
13:45:02,035 DEBUG [org.springframework.web.servlet.DispatcherServlet] - DispatcherServlet with name 'testapp2' determining Last-Modified value for [/WEB-INF/pages/apiForm.jsp]
13:45:02,038 DEBUG [org.springframework.web.servlet.DispatcherServlet] - No handler found in getLastModified
13:45:02,038 DEBUG [org.springframework.web.servlet.DispatcherServlet] - DispatcherServlet with name 'testapp2' processing request for [/WEB-INF/pages/apiForm.jsp]
13:45:02,038 WARN [org.springframework.web.servlet.PageNotFound] - No mapping found for HTTP request with URI [/WEB-INF/pages/apiForm.jsp] in DispatcherServlet with name 'testapp2'
13:45:02,045 DEBUG [org.springframework.web.servlet.DispatcherServlet] - Successfully completed request
13:45:02,048 DEBUG [org.springframework.web.servlet.DispatcherServlet] - Successfully completed request

this is how my dispatcher.xml look like..

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

This question is related to spring spring-mvc servlet-dispatching

The answer is


"/openStudentPage" is the page that i want to open first, i did :

 @RequestMapping(value = "/", method = RequestMethod.GET)
    public String index(Model model) {
     return "redirect:/openStudentPage";
    }

@RequestMapping(value = "/openStudentPage", method = RequestMethod.GET)
public String listStudents(Model model) {
    model.addAttribute("student", new Student());
    model.addAttribute("listStudents", this.StudentService.listStudents());
    return "index";
}

I think I read the entire internet to figure out how to get sitemesh to handle my html paths without extension + API paths without extension. I was wrapped up in a straight jacket figuring this out, every turn seemed to break something else. Then I finally came upon this post.

<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet>
    <servlet-name>jsp</servlet-name>
    <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
</servlet>

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

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

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

Enter this in your dispatcher-servlet.xml

<mvc:default-servlet-handler/>

you will get a No mapping found for HTTP request with URI error

if you scanned the wrong package

e.g your controller is in my.package.abc but you mistakenly put

<context:component-scan base-package="my.package.efg*" />

or

@ComponentScan("my.package.efg*")

which in the sense, your controller doesn't get scanned into the web application context, when request comes in not just url, but the entire class is not found!


What you need is to have a controller that responds to the url first which then renders your jsp. See this link for a solution.


I had the same problem, Of course there was a little difference. The story was that when I was removing the below line:

<mvc:resources mapping="/resources/**" location="classpath:/resources/" />

Everything was OK but in presence of that line the same error raise.

After some trial and error I found I have to add the below line to my spring application context file:

<mvc:annotation-driven />

Hope it helps!


Same answer as Brad Parks... more text though

I had the exact same problem and tried the above solutions along with many others, all with negative results. I even started out with a new, fresh Dev env and simply installed a spring-mvc-template and tried to run it directly after install (should work, but failed for me)

For me the problem was that I was using jdk1.6 in my project, but my selected execution environment in eclipse was jdk1.7. The solution was to change the project specific execution environment settings so that this project is set to jdk1.6. Right click project --> Properties --> Java Compiler --> Check "Enable project specific settings" if it's not already checked --> select the appropriate jdk (or add if it's not installed).

I hope this can help someone and save that persons time, because I have spent the last few days looking for the answer on every corner of the Internet. I accidently stumbled upon it myself when I started to get desperate and look for the solution in areas where it (according to my brain) was less likely to be found. =)

My 2 cents. Thanks!

Edit1: Use project specific settings

Edit2: Just realized Brad Parks already answered this in this very thread. Well, at least I got the "Editor"-badge out of this one =D


This could also happen when your app doesn't actually compile, yet it's still launched in Tomcat. When I saw this happen, it wasn't compiling because the project had a "project specific" JDK specified, and the code was checked out on a machine that didn't have that specific JDK. Eclipse defaulted to a JRE instead, not a JDK, and then the app wasn't compiled.

To fix it in our specific case, we just turned off "Project Specific Settings" here:

"Project | Properties | Java Compiler"

Here's more detailed info on how to do this: https://stackoverflow.com/a/2540730/26510


With Spring 3.1 and Tomcat 7 I got next error:

org.springframework.web.servlet.DispatcherServlet noHandlerFound No mapping found for HTTP request with URI [/baremvc/] in DispatcherServlet with name 'appServlet'

And I needed to add to web.xml next configuration:

<welcome-file-list>
    <welcome-file/>
</welcome-file-list>

And the application worked!


Just add <mvc:default-servlet-handler /> to your DispatcherServlet configuration and you are done!


Unfortunately, this is a rather broad class error message. Yet another thing which could be going wrong is if you are missing some classes/jars. For example, if you are missing the spring-expression jar file, the dispatch-servlet is not going to be able to locate your controller no matter how hard you try and how correct everything else is configured.


Simple check can be made. I am currently using Spring MVC architecture along with hibernate. I had missed writing @Controller annotations just above class name. This was causing the problem for me.

@Controller
public class MyClass{
    ...
}

Hope this simple check solves your problem.


Yes, I know I'm late to this party but it might help others.

The servlet container chooses the mapping based on the longest path that matches. So you can put this mapping in for your JSPs and it will be chosen over the /* mapping.

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

Actually for Tomcat that's all you'll need since jsp is a servlet that exists out of the box. For other containers you either need to find out the name of the JSP servlet or add a servlet definition like:

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

I have encountered this problem in Eclipse Luna EE. My solution was simply restart eclipse and it magically started loading servlet properly.


change the your servlet name dispatcher to any other name .because dispatcher is predefined name for spring3,spring4 versions.

<servlet>
    <servlet-name>ahok</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>ashok</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

Solution that helped me is: do not map DispatcherServlet to /*, map it to /. Final config is then:

<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        ...
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

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

Examples related to spring

Are all Spring Framework Java Configuration injection examples buggy? Two Page Login with Spring Security 3.2.x Access blocked by CORS policy: Response to preflight request doesn't pass access control check Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified Spring Data JPA findOne() change to Optional how to use this? After Spring Boot 2.0 migration: jdbcUrl is required with driverClassName The type WebMvcConfigurerAdapter is deprecated No converter found capable of converting from type to type

Examples related to spring-mvc

Two Page Login with Spring Security 3.2.x ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean Spring 5.0.3 RequestRejectedException: The request was rejected because the URL was not normalized The type WebMvcConfigurerAdapter is deprecated RestClientException: Could not extract response. no suitable HttpMessageConverter found Spring boot: Unable to start embedded Tomcat servlet container UnsatisfiedDependencyException: Error creating bean with name 8080 port already taken issue when trying to redeploy project from Spring Tool Suite IDE Error creating bean with name 'entityManagerFactory' defined in class path resource : Invocation of init method failed Difference between the annotations @GetMapping and @RequestMapping(method = RequestMethod.GET)

Examples related to servlet-dispatching

What is Dispatcher Servlet in Spring? No mapping found for HTTP request with URI [/WEB-INF/pages/apiForm.jsp]