将SpringMVC与JSP页面一起使用时遇到错误500

时间:2019-04-03 18:24:19

标签: spring spring-boot spring-mvc jsp tomcat

我正在尝试使用SpringMVC使用JSP和SpringBoot创建UI。 正确完成所有配置后,我仍然收到错误-“ java.lang.ClassNotFoundException:org.eclipse.jdt.internal.compiler.env.INameEnvironment”,我已经做了很多尝试来解决它,但是仍然无法正常工作。如果有人可以帮助我。预先谢谢你。

我的文件结构 enter image description here

我的控制器

field1

我的SpringBoot页面

    package com.capgemini.PACE.PACE;

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

    @Controller
    public class HelloController {

@RequestMapping("/")
public String Hello()
{
    return "/Hello";
}
    }

我的pom.xml

    package com.capgemini.PACE.PACE;

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

    @SpringBootApplication
    public class PaceApplication {

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

    }

我的JSP页面

    <?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.3.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.capgemini.PACE</groupId>
<artifactId>PACE</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>PACE</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.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>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
    </dependency>
</dependencies>

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

我的application.properties

    <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <h1>HEllo!!</h1>

    </body>
    </html>

我试图在pom.xml中添加这些依赖项仍然无法正常工作

    server.port=8082
    spring.mvc.view.prefix = /WEB-INF/views/
    spring.mvc.view.suffix = .jsp
    spring.mvc.static-path-pattern=/resources/**

我遇到错误-

    <dependency>
        <groupId>javax.servlet.jsp.jstl</groupId>
        <artifactId>javax.servlet.jsp.jstl-api</artifactId>
        <version>1.2.1</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.1</version>

1 个答案:

答案 0 :(得分:0)

In my case it worked by adding this dependency in pom.xml file.
It is needed to compile jsp don't know why tomcat-embed-jasper version is not working
        <dependency>
            <groupId>org.eclipse.jdt.core.compiler</groupId>
            <artifactId>ecj</artifactId>
            <version>4.6.1</version>
            <scope>provided</scope>
        </dependency>