检查JSP片段是否已设置
我遇到了以下使用 JSP 的教程 JSP 技巧使模板更容易?创建页面模板(我怎么错过了这么久?!?)。然而,经过一些搜索后,我似乎无法弄清楚如何(或者是否可能)检查 JSP 片段是否已设置。
以下是我尝试执行的操作的示例:
我有一个名为 default.tag
的模板。它有 2 个 JSP 属性定义如下:
<%@attribute name="title" fragment="true" required="true" %>
<%@attribute name="heading" fragment="true" %>
然后在页面的代码中,我将页面的
<c:choose>
<c:when test="${true}">
<jsp:invoke fragment="heading" />
</c:when>
<c:otherwise>
<jsp:invoke fragment="title" />
</c:otherwise>
</c:choose>
在我有
的地方,我希望能够检查 标题是否
片段已被设置以便显示它,但如果没有,则默认为 title
片段。
I came across the following tutorial JSP tricks to make templating easier? for using JSP to create page templates (how have I missed this for so long?!?). However, after doing some searching, I cannot seem to figure out how (or if it is possible) to check if a JSP fragment has been set.
Here is an example of what I'm trying to do:
I have a template named default.tag
. It has 2 JSP attributes defined as follows:
<%@attribute name="title" fragment="true" required="true" %>
<%@attribute name="heading" fragment="true" %>
Then in the code of the page, I have the <title>
element of the page set to <jsp:invoke fragment="title" />
. Then later down the page, I have the following:
<c:choose>
<c:when test="${true}">
<jsp:invoke fragment="heading" />
</c:when>
<c:otherwise>
<jsp:invoke fragment="title" />
</c:otherwise>
</c:choose>
Where I have <c:when test="${true}">
, I want to be able to check if the heading
fragment has been set in order to display it, but if not, then default to the title
fragment.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在做了更多的混乱之后,我将回答我自己的问题。事实证明,赋予
属性
的名称实际上也变成了一个变量。因此,我可以做以下事情:这就是我需要做的。看来我只是想让事情变得比需要的更难!
After doing some more messing around, I'm going to answer my own question. It turns out that the name given to the
attribute
actually becomes a variable as well. Therefore, I can do the following:That was all I needed to do. Seems like I was just trying to make it harder than it needed to be!