Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用STS4.2.1在springboot中添加jsp页面并将其连接到控制器_Java_Spring Boot_Spring Mvc - Fatal编程技术网

Java 如何使用STS4.2.1在springboot中添加jsp页面并将其连接到控制器

Java 如何使用STS4.2.1在springboot中添加jsp页面并将其连接到控制器,java,spring-boot,spring-mvc,Java,Spring Boot,Spring Mvc,我用maven创建了一个springboot应用程序,并在这里添加了一个控制器 package ml.developer45.boot.ctrl; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.config.annotation.Enabl

我用maven创建了一个springboot应用程序,并在这里添加了一个控制器

package ml.developer45.boot.ctrl;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

@Controller
public class MainCtrl {

    @RequestMapping("/")
    public String hello()
    {
        return "index";
    }
}
这是我使用springapplication.run方法的主要类

package ml.developer45.boot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}
这是我的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 http://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.4.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>ml.developer45</groupId>
    <artifactId>demo-app</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

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

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

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

    <packaging>war</packaging>
</project>
这是控制台输出,没有GET/WEB-INF/views/index.jsp错误的映射

Picked up _JAVA_OPTIONS:   -Dawt.useSystemAAFontSettings=gasp

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

2019-05-03 17:40:36.936  INFO 21051 --- [           main] ml.developer45.boot.DemoApplication      : Starting DemoApplication on 45davy-PC with PID 21051 (/home/davy/Documents/workspace-spring-tool-suite-4-4.2.1.RELEASE/demo/target/classes started by davy in /home/davy/Documents/workspace-spring-tool-suite-4-4.2.1.RELEASE/demo)
2019-05-03 17:40:36.941  INFO 21051 --- [           main] ml.developer45.boot.DemoApplication      : No active profile set, falling back to default profiles: default
2019-05-03 17:40:43.804  INFO 21051 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2019-05-03 17:40:43.890  INFO 21051 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-05-03 17:40:43.890  INFO 21051 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.17]
2019-05-03 17:40:44.085  INFO 21051 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-05-03 17:40:44.085  INFO 21051 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 7050 ms
2019-05-03 17:40:44.814  INFO 21051 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-05-03 17:40:45.200  INFO 21051 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2019-05-03 17:40:45.208  INFO 21051 --- [           main] ml.developer45.boot.DemoApplication      : Started DemoApplication in 8.862 seconds (JVM running for 9.429)
2019-05-03 17:40:55.213  INFO 21051 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2019-05-03 17:40:55.213  INFO 21051 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2019-05-03 17:40:55.222  INFO 21051 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 9 ms
2019-05-03 17:40:55.289  WARN 21051 --- [nio-8080-exec-1] o.s.web.servlet.PageNotFound             : No mapping for GET /WEB-INF/views/index.jsp
2019-05-03 17:40:56.020  WARN 21051 --- [nio-8080-exec-2] o.s.web.servlet.PageNotFound             : No mapping for GET /WEB-INF/views/index.jsp
我试图从我的控制器中呈现src/main/webapp/WEB-INF/views文件夹中的jsp页面,但一直失败,我甚至从jar将打包更改为war,但也失败了!!
请帮帮我

我有了一个解决方案,我在tomcat嵌入jasper中添加了一个依赖项

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

org.apache.tomcat.embed
汤姆卡特·贾斯珀
<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
</dependency>