代码:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<body bgcolor="white">
<jsp:useBean id="clock" class="java.util.Date" />
<c:choose>
<c:when test="${clock.hours < 12}">
<h1>Good morning!</h1>
</c:when>
<c:when test="${clock.hours < 18}">
<h1>Good day!</h1>
</c:when>
<c:otherwise>
<h1>Good evening!</h1>
</c:otherwise>
</c:choose>
Welcome to our site, open 24 hours a day.
正常情况:
运行时会根据当时的时间 clock.hours 来判断当前时间,以便输出不同语句,早上输出Good morning! 中午输出 Good day! 晚上输出Good evening!
如:
Good morning!
Welcome to our site, open 24 hours a day.
问题:
第三行: <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
总是报错如下:
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
在这里先解释一下uri(Uniform Resoure Identifier):用来标识库的位置的.
错误说:uri不能在web.xml或jar文件中被解析.
由于这时致命错误(fatal error)程序无法被执行.
如果去掉这一行,程序就找不到jstl库,编译能通过,也能执行,但是所有的jstl组建都失效
运行结果会这样:
Good morning!
Good day!
Good evening!
Welcome to our site, open 24 hours a day.
这显然时不对的.
解决方案:
我注意到在第三行的上放有一段自动生成的注释:
<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>
如果要用到jstl的话要在工程视图的库接点上添加JSTL 1.1库.
展开工程视图中当前工程 -> 右键"库"接点 -> 添加库 -> JSTL 1.1 -> 确认
然后在重新执行就OK了
本文介绍了解决Java Web项目中JSTL库无法加载的问题。通过在项目中正确配置JSTL库,可以实现根据不同时间段显示相应问候语的功能。
2万+

被折叠的 条评论
为什么被折叠?



