Warm tip: This article is reproduced from stackoverflow.com, please click
java jsp maven spring xml

WARNING: No mapping found for HTTP request with URI[] in DispatcherServlet with name []

发布于 2020-04-13 10:01:11

I'm really new to Spring framework and I'm struggling why I'm getting this warning. I have looked at the questions at StackOverflow and coderanch but it seems that I can't find my error. I even tried to watch a youtube Spring MVC tutorial twice and I'm doing the same thing as the Youtuber does but I'm still getting this error. I would really appreciate it if you guys could help me. I will put my codes below.

pom.xml

  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.telusko</groupId>
  <artifactId>DemoMVC2</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>DemoMVC2 Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
     <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.1.8.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.1.8.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.36</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
  </dependencies>
  <build>
    <finalName>DemoMVC2</finalName>
  </build>
</project>

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>telusko</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>telusko</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

telusko-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:component-scan base-package="com.telusko"></ctx:component-scan>
</beans>

index.jsp

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

addController.java

package com.telusko;

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

@Controller
public class addController {
    @RequestMapping("/add")
    public void add() {
        return "display.jsp";
    }
}

display.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

    I'm here

</body>
</html>
Questioner
noseless
Viewed
69
161 2020-02-04 18:16

This is the servlet you created. You have created a telusko servlet on the DispatcherServlet class. And then you mapped it with /. When the application starts, it does not find a function mapped to /. So you will have to readjust your web.xml file