将 Spring MVC 与 JSP 页面一起使用时出现错误 500
Posted
技术标签:
【中文标题】将 Spring MVC 与 JSP 页面一起使用时出现错误 500【英文标题】:getting error 500 while using SpringMVC with JSP page 【发布时间】:2019-08-25 09:04:44 【问题描述】:我正在尝试使用 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";
我的 SpringBoot 页面
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);
我的 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.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>
我的应用程序.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
【问题讨论】:
【参考方案1】: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>
【讨论】:
你拯救了我的一天...非常感谢。以上是关于将 Spring MVC 与 JSP 页面一起使用时出现错误 500的主要内容,如果未能解决你的问题,请参考以下文章
与 Spring Boot 一起使用时,JSP 页面中的 contextPath 为空