带有 JSTL 的 JSP 在 Spring Boot 应用程序中无法在 tomcat 8 上工作 [英] JSP with JSTL not working on tomcat 8 in a Spring Boot Application
问题描述
我在 pom.xml 中包含了这些依赖项.
I have include these dependency in pom.xml.
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
我仍然收到 javax.servlet.ServletException: java.lang.NoSuchMethodError: org.apache.el.lang.ELSupport.coerceToType(Ljavax/el/ELContext;Ljava/lang/Object;Ljava/lang/Class;)ljava/lang/Object;
Still i am getting javax.servlet.ServletException: java.lang.NoSuchMethodError: org.apache.el.lang.ELSupport.coerceToType(Ljavax/el/ELContext;Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
我还在 pom.xml 中添加了一个依赖项.
I also included one more dependency in pom.xml.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
然后错误更改为 An exception occurred processing JSP page/WEB-INF/views/index.jsp at line 7 4: <%@ page session="false" %> [[[[ JSTL CODE USING EXPRESSION LANGUAGE]]]
Then the error changed to An exception occurred processing JSP page /WEB-INF/views/index.jsp at line 7 4: <%@ page session="false" %> [[[[ JSTL CODE USING EXPRESSION LANGUAGE]]]
在 eclipse ide 中一切正常,但无法在单独的 tomcat 服务器上进行部署.
Everything is working fine in eclipse ide but not working on deploying on separate tomcat server.
推荐答案
由于 tomcat-embed-el-8.0.32.jar 在您的 中的存在,您得到以下错误Tomcat 8.0\webapps\AppName\WEB-INF\lib
文件夹.
You are getting below error because of the presence of tomcat-embed-el-8.0.32.jar in your Tomcat 8.0\webapps\AppName\WEB-INF\lib
folder.
javax.servlet.ServletException: java.lang.NoSuchMethodError:
org.apache.el.lang.ELSupport.coerceToType(Ljavax/el/ELContext;Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
此错误是由于Tomcat提供的ELSupport.class
与tomcat-embed-el-8.0.32.jar冲突造成的> 存在于应用程序 lib
目录中,因此您会在 Tomcat 中遇到该错误.它在 Eclipse 中运行良好,因为它使用嵌入式服务器.
This error is due to the conflict between the ELSupport.class
provided by Tomcat and tomcat-embed-el-8.0.32.jar present in the applications lib
directory, hence you get that error in Tomcat. And it works fine in Eclipse since it uses embedded server.
要解决此问题,请在您的 pom.xml
中添加以下代码:
To fix this issue add below code in your pom.xml
:
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-el</artifactId>
<scope>provided</scope>
</dependency>
当您将 tomcat-embed-el
依赖项添加为 scope=required
时,tomcat-embed-el-8.0.32.jar不会添加到您的 \AppName\WEB-INF\lib
文件夹中.
When you add tomcat-embed-el
dependency as scope=required
then the tomcat-embed-el-8.0.32.jar will not be added into your \AppName\WEB-INF\lib
folder.
有关信息,请查看 Spring-Boot 的 Github 存储库上的此问题.
For information check this Issue on Spring-Boot's Github repository.
您也可以使用这些示例应用:
Also you can use these sample apps:
- Spring-Boot-Jsp-Demo 已配置使用
InternalResourceViewResolver
bean. - spring-boot-sample-tomcat-jsp 使用
application.properties
配置,就像在 spring-boot 示例应用程序中一样.
- Spring-Boot-Jsp-Demo configured with
InternalResourceViewResolver
bean. - spring-boot-sample-tomcat-jsp configured with
application.properties
just like in the spring-boot sample apps.
这篇关于带有 JSTL 的 JSP 在 Spring Boot 应用程序中无法在 tomcat 8 上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!