在使用带有JSP页面的Spring MVC时获得错误500

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在使用带有JSP页面的Spring MVC时获得错误500相关的知识,希望对你有一定的参考价值。

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

我的文件结构enter image description here

我的控制器

    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";
}
    }

我的Spring Boot页面

    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);
}

    }

我们会帮忙的

    <?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>

我的JSP页面

    <%@ 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>

我的application.properties

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

我试过在pom.xml中添加这些依赖项仍然无法获得相同的错误

    <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>

我收到错误 -

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Wed Apr 03 14:06:02 EDT 2019
There was an unexpected error (type=Internal Server Error, status=500).
org/eclipse/jdt/internal/compiler/env/INameEnvironment
答案
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>

以上是关于在使用带有JSP页面的Spring MVC时获得错误500的主要内容,如果未能解决你的问题,请参考以下文章

spring mvc jsp怎么获得ModelAndView设置的值 急急急!

Spring MVC UTF-8 编码

Spring mvc @PathVariable

如何在 Spring Boot 中与 Spring MVC 一起提供遗留的 jsp 页面?

Spring MVC 控制器如何绑定到 JSP 页面?

shiro+springmvc集成时,配置loginUrl='login.jsp',但是login.jsp页面在WEB-INF 目录下,导致无法显示