绝对uri:http://java.sun.com/jstl/core无法在此应用程序部署的web.xml或jar文件中



我需要一些帮助,我想做一个程序,并使用

if(session.getAttribute("logged")!="1"){ 
 String err="You must be logged in!!"; 
 request.setAttribute( "error", err ); 
 String nextJSP = "/login.jsp"; 
 RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP); 
dispatcher.forward(request,response); }

%>

在一个jsp中,但我的老板让我使用jstl,所以我把它改为:

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
 <c:if test="${session.getAttribute('logged')!=null}"> 
      <jsp:forward page="login.jsp">
      </jsp:forward>
 </c:if>
 <c:if test="${session.getAttribute('logged')==null}">
      <jsp:forward page="princ.jsp"> </jsp:forward>
 </c:if>

我得到了一个严重的错误:

 "org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application " 

我在互联网上搜索了一些修复程序,我把javax.servlet.jsp.jsl-api-1.2.1-javadoc.jar放在了我的库中,甚至把javaee.jar放在Tomcat库中,但仍然没有解决方案,有人能帮我吗?附言:我得到了适用于Web开发人员的Eclipse Java EE IDE。(INDIGO)Tomcat 7.08

您的taglib URI错误。

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

这个URI来自旧的EOL'ed JSTL 1.0库。由于JSTL 1.1,您需要在路径中添加一个额外的/jsp,因为标签库的内部工作方式已更改,因为EL部分已从JSTL移动到JSP:

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

此外,您试图在/WEB-INF/lib中删除的JAR文件是错误的。javax.servlet.jsp.jstl-api-1.2.1-javadoc.jar只包含JSTL javadocs,而javaee.jar包含整个Java EE API,这可能是desstreus,因为Tomcat已经提供了它的一部分(JSP/Servlet),这可能会发生冲突。

将它们全部移除。您需要jstl-1.2.jar文件。

另请参阅:

  • 我们的JSTL标签wiki页面

此外,代替

<c:if test="${session.getAttribute('logged')!=null}">  

使用以下之一

<c:if test="${sessionScoped.logged != null}">  
<c:if test="${sessionScoped[logged] != null}">
<c:if test="${logged != null}">

我认为您应该包括jstl-1.2.jar.

最新更新