Is there a JSTL tag specifically for displaying messages, and only if there are messages to display? So that I don't have to surround the displaying with an "c:if" tag.

If so, how do I use it? How should I add the messages to be displayed?

有帮助吗?

解决方案

This sounds like a job for c:out. For example, this should display the value of person.name, or nothing if it is null.

    <c:out value="${person.name}" />

If you want to display a default value in the case of a null, then:

    <c:out value="${person.name}" default="no name" />

or

    <c:out value="${person.name}">no name</c:out>

(If this doesn't answer your question, you need to be more explicit about what you mean by "messages" ... and how you want them to be displayed.)


If you have zero or more messages in a collection:

    <c:forEach items="${messages}" var="message">
        <c:out value="${message}"/>
    </c:forEach>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top