Reputation: 19
I have been searching a way to fix this error but couldn't find the answer. Kept getting this error:
Apr 06, 2018 1:40:36 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/spring-tutorial/] in DispatcherServlet with name 'offers'
I am running on JDK 1.8, tomcat 8.0, and running on the latest eclipse IDE.
My web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID"
version="2.5">
<display-name>spring-tutorial</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<description></description>
<display-name>offers</display-name>
<servlet-name>offers</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>offers</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
My offers-servlet.xml
<?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.2.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<mvc:default-servlet-handler/>
<mvc:annotation-driven></mvc:annotation-driven>
<context:component-scan
base-package="com.emenpy.spring.web.controllers">
</context:component-scan>
<bean id="jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsps/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
My OffersController.java
package com.emenpy.spring.web.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class OffersController {
@RequestMapping("/")
public String showHome() {
return "home";
}
}
And my home.jsp
<html>
<body>
<h2>Hello World!</h2>
</body>
</html>
Here is my directory tree: enter image description here
Upvotes: 0
Views: 56
Reputation: 136
Your jsp should be called "home.jsp" instead of "index.jsp"
your package name in scan is
<context:component-scan
base-package="com.emenpy.spring.web.controllers">
</context:component-scan>
when it should be as your directory tree shows
<context:component-scan
base-package="com.cuong.spring.web.controllers">
</context:component-scan>
as the scaning didn't find your controller the mapping wasn't done
Upvotes: 1