0

No mapping found for HTTP request with URI [/demoApp/index.jsp] in DispatcherServlet with name 'newApp'

I am getting this error please help.I am using Tomcat v9.0 server.

index.jsp

<html>
<body>
<form action="add">
<input type="text" name="t1"><br>
<input type="text" name="t2"><br>
<input type="submit"><br>

</form>
</body>
</html>

web.xml


<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>

  <display-name>Archetype Created Web Application</display-name>

  <servlet>
        <servlet-name>newApp</servlet-name>
        <servlet-class>

            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>newApp</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>


</web-app>

newApp-servlet.xml

<?xml version = "1.0" encoding = "UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:ctx="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-2.5.xsd ">
     <mvc:annotation-driven />


    <ctx:annotation-config></ctx:annotation-config>
    <ctx:component-scan base-package="com.newApp"></ctx:component-scan>
</beans>

AddController.java

package com.newApp;
import java.lang.*;

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

@Controller
public class AddController {
    @RequestMapping("/add")
    public void add() 
    {
        System.out.println("I am good");
    }

}

program should print "I am good" on the console but it is showing error on browser "The origin server did not find a current representation for the target resource or is not willing to disclose that one exists." on the console it is showing "No mapping found for HTTP request with URI [/demoApp/add] in DispatcherServlet with name 'newApp'".

This error accures when i click on submit button on jsp page.

2 Answers2

0

If you want to use view technology like jsp. You could add bean definition of InternalResourceViewResolver class into your spring configuration file

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

see official docs

Anthony
  • 571
  • 3
  • 11
  • Still the same error. I can not understand why this is happening, please help. – Technical Untechnical Aug 05 '19 at 15:56
  • Maybe is incorrect url mapping? What is application context used during deploy at the server? You could see related [question](https://stackoverflow.com/questions/43931383/the-origin-server-did-not-find-a-current-representation-for-the-target-resource), it may have similar issue – Anthony Aug 05 '19 at 19:48
0

I got the same issue and resolved it. Please add missing folder src/main/java [add package name (for example: com.dev) while adding a class] and then add the java class in that instead of src/main/resource folder. This is the culprit. Let me know for any issue at parixitk28@gmail.com.

Parixit K
  • 1
  • 1