此应用程序没有 /error 的显式映射,因此您将其视为后备。- Spring Boot - JSP

Nag*_*eja 1 spring jsp tomcat spring-mvc spring-boot

我是 Spring Boot 的新手,尝试使用 JSP 和 Spring Boot 构建一个 Web 应用程序,但出现了我已准确给出路径的回退错误。

请参考以下链接。我在其中创建了 WEb_INF 和路径 https://drive.google.com/file/d/1-qkoy49zIZe-Y6-zPeAn9g2aRGaDHt01/view?usp=sharing

文件CustomerContoller.java

package com.javabrains.controller;

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

@Controller
@RequestMapping("/customer")
public class CustomerController {

    public String hello(ModelMap Model) {
        return "list";
    }
}
Run Code Online (Sandbox Code Playgroud)

文件application.properties

spring.mvc.view.prefix: /WEB-INF/jsp/
spring.mvc.view.suffix: .jsp
Run Code Online (Sandbox Code Playgroud)

文件pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.8.RELEASE</version>
        <relativePath/> <!-- Look up parent from repository -->
    </parent>
    <groupId>com.javabrains</groupId>
    <artifactId>javabrains</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>WebDemo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>
Run Code Online (Sandbox Code Playgroud)

堆栈跟踪

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.8.RELEASE)

2019-09-08 11:32:00.571  INFO 6484 --- [  restartedMain] com.javabrains.WebDemoApplication        : Starting WebDemoApplication on NagaTeja with PID 6484 (C:\Users\nagat\workspace1\WebDemo\target\classes started by nagat in C:\Users\nagat\workspace1\WebDemo)
2019-09-08 11:32:00.575  INFO 6484 --- [  restartedMain] com.javabrains.WebDemoApplication        : No active profile set, falling back to default profiles: default
2019-09-08 11:32:00.626  INFO 6484 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2019-09-08 11:32:00.626  INFO 6484 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2019-09-08 11:32:01.644  INFO 6484 --- [  restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.ws.config.annotation.DelegatingWsConfiguration' of type [org.springframework.ws.config.annotation.DelegatingWsConfiguration$$EnhancerBySpringCGLIB$$b5bc3870] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-09-08 11:32:01.699  INFO 6484 --- [  restartedMain] .w.s.a.s.AnnotationActionEndpointMapping : Supporting [WS-Addressing August 2004, WS-Addressing 1.0]
2019-09-08 11:32:02.286  INFO 6484 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2019-09-08 11:32:02.321  INFO 6484 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-09-08 11:32:02.322  INFO 6484 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.24]
2019-09-08 11:32:02.605  INFO 6484 --- [  restartedMain] org.apache.jasper.servlet.TldScanner     : 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.
2019-09-08 11:32:02.612  INFO 6484 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-09-08 11:32:02.613  INFO 6484 --- [  restartedMain] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1987 ms
2019-09-08 11:32:02.904  INFO 6484 --- [  restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-09-08 11:32:03.235  INFO 6484 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2019-09-08 11:32:03.310  INFO 6484 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2019-09-08 11:32:03.313  INFO 6484 --- [  restartedMain] com.javabrains.WebDemoApplication        : Started WebDemoApplication in 3.191 seconds (JVM running for 3.903)
2019-09-08 11:32:16.663  INFO 6484 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2019-09-08 11:32:16.663  INFO 6484 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2019-09-08 11:32:16.671  INFO 6484 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 8 ms
Run Code Online (Sandbox Code Playgroud)

我希望list.jsp文件应该成功运行,没有任何问题。我该如何解决这个问题?

Avi*_*rua 5

什么也没有发生,因为您没有在控制器内的方法上添加任何映射。因此,在类似的方法上添加地图

@GetMapping(value="")
public String hello(ModelMap Model) {
    return "list";
}
Run Code Online (Sandbox Code Playgroud)

运行项目后,打开浏览器并点击localhost:8080/customer