Сопоставление выполнено по мере необходимости, но выдается ошибка 404, что я делаю не так - PullRequest
0 голосов
/ 09 июля 2020

Я новичок в Spring и пробую свой первый Spring MVC. Просто пытаюсь сопоставить один файл с именем «display. jsp» и выдает сообщение «Сопоставление не найдено». Я много сделал, и вроде ничего не работает. Что я делаю не так?

, насколько мне известно, проблема может заключаться либо в отображении.

Запуск в Eclipse 2019-20 с JDK 1.8. Ниже представлены все файлы, которые я создал.

Exception Stacktrace:
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Jul 06, 2020 6:43:23 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8081"]
Jul 06, 2020 6:43:23 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8010"]
Jul 06, 2020 6:43:23 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2084 ms
Jul 06, 2020 6:43:28 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'demo'
Jul 06, 2020 6:43:28 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'demo': initialization started
Jul 06, 2020 6:43:28 PM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'demo-servlet': startup date [Mon Jul 06 18:43:28 IST 2020]; root of context hierarchy
Jul 06, 2020 6:43:28 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/demo-servlet.xml]
Jul 06, 2020 6:43:29 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache
INFO: Looking for @ControllerAdvice: WebApplicationContext for namespace 'demo-servlet': startup date [Mon Jul 06 18:43:28 IST 2020]; root of context hierarchy
Jul 06, 2020 6:43:29 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache
INFO: Looking for @ControllerAdvice: WebApplicationContext for namespace 'demo-servlet': startup date [Mon Jul 06 18:43:28 IST 2020]; root of context hierarchy
Jul 06, 2020 6:43:29 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'demo': initialization completed in 1490 ms
Jul 06, 2020 6:43:29 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/Demo/add] in DispatcherServlet with name 'demo'

Вот мои файлы

pom. xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 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.sudeep</groupId>
 <artifactId>SpringMVC</artifactId>
 <packaging>war</packaging>
 <version>0.0.1-SNAPSHOT</version>
 <name>SpringMVC 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>Demo</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>demo</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
  </servlet>
  <servlet-mapping>
        <servlet-name>demo</servlet-name>
        <url-pattern>/</url-pattern>
  </servlet-mapping>
  
</web-app>

индекс. jsp

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

AddController. java

package com.sudeep;

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

демонстрационный сервлет. 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:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd     
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.1.xsd">
    
    <mvc:annotation-driven />
    <context:component-scan base-package="com.sudeep"></context:component-scan>
</beans>

дисплей. jsp

 <%@ 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>Insert title here</title>
</head>
<body>
    I am here
</body>
</html>
...