This article is a mirror article of machine translation, please click here to jump to the original article.

View: 13032|Reply: 0

[JavaEE] Usage of the jstl tag <c:if>

[Copy link]
Posted on 1/4/2015 1:28:11 PM | | |

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>






Previous:JSP page jump encyclopedia
Next:Traversal of List collection in java and comparative analysis of two implementation classes
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com