0

I've seen this question asked a lot of times and I also see lots of different answers. Unfortunately, nothing seems to be working for me. Please help.

I get the error Aug 18, 2016 1:03:09 PM org.springframework.web.servlet.PageNotFound noHandlerFound No mapping found for HTTP request with URI [/TestServlet/] in DispatcherServlet with name 'offers'

I've tried the same thing around 3 times. Please do advice on how I can proceed.

My web.xml file is as below

<?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>TestServlet</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 is as follows

<?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-4.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-4.2.xsd">


    <mvc:annotation-driven></mvc:annotation-driven>
    <context:component-scan
        base-package="com.sharat.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>

This is my home.jsp file

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>My JSP</title>
</head>
<body>
Hi There
</body>
</html>

This is my OffersController source file

package com.sharat.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";
        }
}

Please help me understand where i may be wrong. I checked the package name where my controller is located and seems to be correct. I also added the and the context component scan.

Thank you.

user2951259
  • 23
  • 1
  • 6

2 Answers2

0

Change your servlet dispatcher mapping to serve all incoming requests:

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

and in order to access "/offers" URI you need to edit your controller class:

@Controller
public class OffersController {
        @RequestMapping("/offers")
        public String showHome(){
            return "home";
        }
}
WeMakeSoftware
  • 9,039
  • 5
  • 34
  • 52
  • Dear Funtik, I tried that but now i get the error Aug 18, 2016 1:48:09 PM org.springframework.web.servlet.PageNotFound noHandlerFound WARNING: No mapping found for HTTP request with URI [/offers/] in DispatcherServlet with name 'offers' I have changed my web.xml servlet mapping to offers /* – user2951259 Aug 18 '16 at 08:19
  • but your URI should be blank. Like localhost:8080/ – WeMakeSoftware Aug 18 '16 at 08:26
  • Is there something i might be doing wrong for it to not be blank ? – user2951259 Aug 18 '16 at 08:37
  • @Futnik - thanks for the reply. I still get the same error though :( – user2951259 Aug 18 '16 at 10:02
0

I still do not know what the issue is. I got it working by installing a completely new version of Eclipse and a new workspace and then using the same code that i originally posted. Weird !

user2951259
  • 23
  • 1
  • 6