org.apache.jasper.JasperException:属性前缀[fn]与任何导入的标记库都不对应

时间:2015-09-04 14:01:09

标签: java servlets web jstl tomcat8

我正在尝试使用IntelliJIDEA 14.1.4部署和运行Hello World应用程序 在Tomcat 8.0.14(Tomcat Server -> Local)上。该项目是使用maven-archetype-webapp创建的,后来又导入了 通过指定pom.xml的路径到IDE。

一切正常,如servlets标记信息中所述,但当我删除以下行时:

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

并将其添加到我的include.jsp中,我遇到了:

org.apache.jasper.JasperException: /WEB-INF/jsp/hello.jsp (line: 18, column: 42) The attribute prefix [fn] does not correspond to any imported tag library

项目结构:

enter image description here

include.jsp

<%-- 'header' file that will be included in every JSP page ensuring the same definitions are included in all our JSPs. --%>
<%@ page session="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

的index.jsp:

<%@ include file="/WEB-INF/jsp/include.jsp" %>
<c:redirect url="/WEB-INF/jsp/hello.jsp"/>

的hello.jsp:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Application Home</title>
  <style>.error {
    color: red;
  }
  .success {
    color: green;
  }</style>
</head>
<body>
<form action="hello" method="post">
  <h1>Hello</h1>

  <p>
    <label for="name">What's your name?</label>
    <input id="name" name="name" value="${fn:escapeXml(param.name)}">
    <span class="error">${messages.name}</span>
  </p>

  <p>
    <label for="age">What's your age?</label>
    <input id="age" name="age" value="${fn:escapeXml(param.age)}">
    <span class="error">${messages.age}</span>
  </p>

  <p>
    <input type="submit">
    <span class="success">${messages.success}</span>
  </p>
</form>
</body>
</html>

问题:

仅添加一行(include.jsp)是不是一个坏主意,这样我可以在需要的地方使用它而不是在每个JSP中添加它,或者因为我缺少的其他东西而导致错误原因?

1 个答案:

答案 0 :(得分:1)

看起来很傻,我错过了导致异常的hello.jsp中的include语句。发布答案是因为我希望将此信息保存在此处以备将来参考。

hello.jsp

中缺少声明
<%@ include file="/WEB-INF/jsp/include.jsp" %>

的hello.jsp:

<%@ include file="/WEB-INF/jsp/include.jsp" %>
<!DOCTYPE html>
....
</body>
</html>