Java 简单 JSP - 根据 TLD 的标签属性无效

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23504719/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 23:26:52  来源:igfitidea点击:

Simple JSP - Attribute invalid for tag according to TLD

javajspjakarta-eejsp-tags

提问by Erran Morad

My project in eclipse -

我在 Eclipse 中的项目 -

enter image description here

在此处输入图片说明

I get the error below when I run MyTagUser.jsp - HTTP Status 500 - /jsp/MyTagUser.jsp(14,0) Attribute subTitle invalid for tag Header according to TLD

运行 MyTagUser.jsp 时出现以下错误 - HTTP Status 500 - /jsp/MyTagUser.jsp(14,0) Attribute subTitle invalid for tag Header according to TLD

org.apache.jasper.JasperException: /jsp/MyTagUser.jsp(14,0) Attribute subTitle 
invalid for tag Header according to TLD

org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
 org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)...etc.

Snippet from Header.jsp -

来自 Header.jsp 的片段 -

<body>
<img src="../images/java_logo.gif"><br>
<em><strong> ${subTitle} </strong></em> <br>
</body>

Snippet from MyTagUser.jsp -

来自 MyTagUser.jsp 的片段 -

<%@ taglib prefix="myTags" tagdir="/WEB-INF/tags"%>
<html>
<head>
</head>
<body>
<myTags:Header  subTitle="Java is the best !!!" />
JSP and Servlets.
</body>
</html>

采纳答案by Erran Morad

You must use the attribute directive in your Header.tag file as show below -

您必须在 Header.tag 文件中使用属性指令,如下所示 -

<body>
<%@ attribute name="subTitle" required="true" rtexprvalue="true" %>
<img src="../images/java_logo.gif"><br>
<em><strong> ${subTitle} </strong></em> <br>
</body>

回答by ?lker Korkut

First Solution:

第一个解决方案:

It seems, you wanted to include header area in your jsp. But it's wrong way.

看来,您想在 jsp 中包含标题区域。但是方法不对。

You should create a header.jsp and then include header.jsp into your MyTagUser.jsp and they should be under the WEB-INF directory(or its sub-directory).

您应该创建一个 header.jsp,然后将 header.jsp 包含到您的 MyTagUser.jsp 中,它们应该位于 WEB-INF 目录(或其子目录)下。

Including method : <%@ include file="WEB-INF/tags/header.jsp"> use this code in MyTagUser.jsp

包含方法: <%@ include file="WEB-INF/tags/header.jsp"> 在 MyTagUser.jsp 中使用此代码

Second Solution :

第二种解决方案:

in your tag file

在你的标签文件中

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

<%@ attribute name="subtitle" required="true" %> this is subTitle attribute

you should define attribute(s). check out http://docs.oracle.com/javaee/1.4/tutorial/doc/JSPTags5.html

您应该定义属性。查看http://docs.oracle.com/javaee/1.4/tutorial/doc/JSPTags5.html