A quick JSTL question. I usually use scriptlets in my jsp pages, but have a conflict due to some other things in my page. I understand you can do something like this using JSTL, although I am not familiar with it. Here is what I would code using java for this:
if (var1.equalsIgnoreCase(var2)) { some html stuff } else { more html }
So can this be converted and translated to be used with JSTL?
Thanks in advance and if you have any questions, just let me know.
The JavaServer Pages Standard Tag Library (JSTL) is a collection of useful JSP tags which encapsulates the core functionality common to many JSP applications. JSTL has support for common, structural tasks such as iteration and conditionals, tags for manipulating XML documents, internationalization tags, and SQL tags.
The < c:if > tag is used for testing the condition and it display the body content, if the expression evaluated is true. It is a simple conditional tag which is used for evaluating the body content, if the supplied condition is true.
JavaServer Pages Tag Library (JSTL) is a set of tags that can be used for implementing some common operations such as looping, conditional formatting, and others. Here we will be discussing how to use the Maven build tool to add JSTL support to a Spring MVC application.
public class JstlView extends InternalResourceView. Specialization of InternalResourceView for JSTL pages, i.e. JSP pages that use the JSP Standard Tag Library. Exposes JSTL-specific request attributes specifying locale and resource bundle for JSTL's formatting and message tags, using Spring's locale and MessageSource ...
You can use <c:choose>
for this. The equalsIgnoreCase()
can be done by lowercasing the both sides by fn:toLowerCase()
.
<c:choose> <c:when test="${fn:toLowerCase(var1) == fn:toLowerCase(var2)}"> Both are equal. </c:when> <c:otherwise> Both are not equal. </c:otherwise> </c:choose>
Or when you're targeting a Servlet 3.0 container (Tomcat 7, Glassfish 3, JBoss AS 6, etc) with a web.xml
declared conform Servlet 3.0, then you can invoke the equalsIgnoreCase()
method.
<c:choose> <c:when test="${var1.equalsIgnoreCase(var2)}"> Both are equal. </c:when> <c:otherwise> Both are not equal. </c:otherwise> </c:choose>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With