内置Jetty配置JSP支持过程中的常见报错

1. 常见报错及解决

内置jetty,jsp支持报错,基本都是jetty、jsp相关依赖配置问题。下面是几个常见报错的例子:

1.1 JSP support not configured

JSP support not configured

解决: 检查pom文件是否有相关依赖,如果没有则添加。注意使用9.3.0.M1版本不行。使用release版本可以,如:

        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-jsp</artifactId>
            <version>9.2.26.v20180806</version>
        </dependency>

注意jetty9.2以后使用apache-jsp

1.2 JSTL标签解析

  • PWC6188: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved
    org.apache.jasper.JasperException: /index.jsp(1,63) PWC6188: The absolute uri: http://java.sun.com/jsp/jstl/core

解决: taglib加上"_rt"

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

更新成:

<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>

更新taglib后,问题解决。

1.3 JSP编译

  • org.apache.jasper.JasperException: Unable to compile class for JSP

JasperException: Unable to compile class for JSP

解决:添加WebXmlConfiguration、AnnotationConfiguration

        Configuration.ClassList classlist = Configuration.ClassList.setServerDefault(server);
        classlist.clear();
        classlist.add("org.eclipse.jetty.webapp.WebXmlConfiguration");
        classlist.add("org.eclipse.jetty.annotations.AnnotationConfiguration");
        server.setHandler(getServletContextHandler());

1.4 JSP实现依赖

  • NoClassDefFoundError: org/apache/jasper/runtime/JspSourceImports
    JasperException NoClassDefFoundError:JspSourceImports

解决:jetty9.2之前jsp实现是Glassfish,9.2之后为Apache,对应依赖jetty-jsp更新为apache-jsp

        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>apache-jsp</artifactId>
            <version>9.4.10.v20180503</version>
        </dependency>

如果jetty-jsp和apache-jsp依赖同时都添加了,则有以下报错:

  • org.apache.jasper.JasperException: javax.el.ELException: java.lang.IllegalAccessException
  • org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: org.apache.jasper.runtime.TagHandlerPool.get(Ljava/lang/Class;)Ljavax/servlet/jsp/tagext/Tag;

NestedServletException

NestedServletException: Handler dispatch failed nested exception is java.lang.NoSuchMethodError: org.apache.jasper.runtime.TagHandlerPool

1.5 EL表达式支持

  • org.apache.jasper.JasperException: javax.servlet.ServletException: javax.el.ELException: Provider com.sun.el.ExpressionFactoryImpl not found
    添加相关依赖即可:
        <dependency>
            <groupId>org.glassfish.web</groupId>
            <artifactId>el-impl</artifactId>
            <version>2.2</version>
        </dependency>

备注:javax.el.javax.el-api javax.el-api-3.0.0.jar中无此ExpressionFactoryImpl实现。

        <dependency>
            <groupId>javax.el</groupId>
            <artifactId>javax.el-api</artifactId>
            <version>3.0.0</version>
        </dependency>

2. 小结

注意相关版本依赖关系即可。pom相关配置:

        <properties>
                <jetty.version>9.4.10.v20180503</jetty.version>
        </properties>

        <!-- web容器- jetty -->
        <!-- https://mvnrepository.com/artifact/org.eclipse.jetty.aggregate/jetty-all -->
        <dependency>
            <groupId>org.eclipse.jetty.aggregate</groupId>
            <artifactId>jetty-all</artifactId>
            <version>${jetty.version}</version>
            <type>pom</type>
        </dependency>
        <!-- jsp实现-->
        <!-- https://mvnrepository.com/artifact/org.eclipse.jetty/apache-jsp -->
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>apache-jsp</artifactId>
            <version>${jetty.version}</version>
        </dependency>

        <!--el表达式-->
        <!-- https://mvnrepository.com/artifact/javax.el/el-api -->
        <dependency>
            <groupId>org.glassfish.web</groupId>
            <artifactId>el-impl</artifactId>
            <version>2.2</version>
        </dependency>

转载于:https://www.cnblogs.com/eaglediao/p/9557719.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值