|
The <c:if> tag must have a test attribute, and when the expression result in test is true, the ontology content will be executed; If false, it will not be executed. For example: ${requestScope.username = = 'admin'}, the result is true if requestScope.username is equal to admin, and false if its content is not equal to admin. Yu Let's take a look at the following examples: <c:if test="${requestScope.username = = 'admin' }"> Hello ADMIN!! body part </c:if> If the name is equal to admin, it will display "Hello ADMIN!! If it is the other way around, the body part of <c:if> will not be executed, so "Hello ADMIN!! //body section" will not be displayed. In addition< the body content of c:if> can be placed in plain text, as well as any JSP program code (Scriptlet), JSP tag or HTML code. In addition to the test property, <c:if> there are two other properties, var and scope. When we execute <c:if>, we can store the result of this judgment in the attribute var; scope sets the attribute range of var. When do the var and scope attributes be used? For example, if the expression is too long, we want to take it apart, or if we need to use the result later, we can also use it to temporarily save the result for later use. Example: <% String amind="Admin"; request.setAttribute("amind",amind); %> <c:if test="${requestScope.amind=='Admin'}" var="condition" scope="request"> Hello Mr. Admin </c:if>
|