我正在尝试使用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
<%-- '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"%>
<%@ include file="/WEB-INF/jsp/include.jsp" %>
<c:redirect url="/WEB-INF/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中添加它,或者因为我缺少的其他东西而导致错误原因?
答案 0 :(得分:1)
看起来很傻,我错过了导致异常的hello.jsp
中的include语句。发布答案是因为我希望将此信息保存在此处以备将来参考。
hello.jsp
<%@ include file="/WEB-INF/jsp/include.jsp" %>
<%@ include file="/WEB-INF/jsp/include.jsp" %>
<!DOCTYPE html>
....
</body>
</html>