jstl使用之/jstl/core_rt和/jstl/core问题

<%@ page import="java.util.List" %>
<%@ page import="com.gfj.entiny.Student" %>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt/jstl/core"%>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <c:forEach items="${stus}" var="stu" varStatus="ss">
        ${stu.id},${stu.name},${stu.age},${stu.address}<br>
    </c:forEach>
<<br>
        </body>
</html>

就是这一段简单的不能再简单的代码,使用idea挂到tomcat后一直报错;

Type Exception Report

Message The absolute uri: http://java.sun.com/jstl/core_rt/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

错误代码如上,查这个错误很久没有头绪,无从下手。

第二天偶然发现一个项目用的标签库为

uri="http://java.sun.com/jstl/core_rt/jstl/core_rt"

试着换成core_rt后,成功解决。

原因:
可能是因为使用了JSP2.0版本, 同时又没有使用JSTL core库的备用版本(RT库)

JSTL core库的有两种taglib伪指令, 其中RT库即是依赖于JSP传统的请求时属性值, 而不是依赖于EL来实现(称为EL库.JSP2.0将支持EL)
JSP中使用 <%@ taglib uri=http://Java.sun.com/jstl/core prefix="c"%>在2.3版本都可以,在2.4就不行了, 这是版本不兼容引起的

jstl存在1.0和1.1的差异问题,用EL建议需要在1.1的版本下:
使用jstl1.1 只需要将
1.0的为

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

换成:

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

猜你喜欢

转载自www.cnblogs.com/gf-jie/p/11892007.html