![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1fb6FOdUgpfSLwqYFmIdHBgi8ijl7_pAMl5WKrgW2A6ln8b8KpMZ8WCZ4Gh11T0y90mz6NPMSXivkShEfXYYvwsgtkh0f06-NfhA-b-gSsdhMsbCmMTKwhJkDcqIn4-A9V9vSePqNKOa7/s1600/jstl.jpg)
What is JSTL ?
It is a standard library of custom tags. In other words, it is a collection of useful
JSP tags which can remove scriplet code from a JSP page.
According to their functionality, these tags are classified into 5 groups.They are
- Core Tags
- Formatting Tags
- SQL Tags
- XML Tags
- JSTL Functions
Before discussing on the above topics in detail, let us see how JSTL can be integrated with our existing project
How to integrate JSTL library in the project?
Maven
Step 1: Update pom
< dependency > < groupid >javax.servlet</ groupid > < artifactid >jstl</ artifactid > < version >1.2</ version > < scope >runtime</ scope > </ dependency > < dependency > < groupid >taglibs</ groupid > < artifactid >standard</ artifactid > < version >1.1.2</ version > < scope >runtime</ scope > </ dependency > |
Step 2: Update viewClass
<bean class = "org.springframework.web.servlet.view.InternalResourceViewResolver" > <property name= "viewClass" value= "org.springframework.web.servlet.view.JstlView" ></property> <property name= "prefix" > <value>/WEB-INF/jsp/</value> </property> <property name= "suffix" > <value>.jsp</value> </property> </bean> |
Step 3: Use JSTL tags in .jsp file
<h1>Welcome message : <c:out value= "${message}" ></c:out></h1> |
Eclipse
Download jstl-1.2.jar (JSP 2.1 containers only i.e. Tomcat 6, otherwise jstl-1.1.jar) fromhttp://repo1.maven.org/maven2/javax/servlet/jstl/1.2/
- or
the interfaces (javax.servlet.jsp.jstl-api-1.2.1.jar) fromhttp://search.maven.org/#browse|707331597 and the actual implementing classes (javax.servlet.jsp.jstl-1.2.2.jar) from http://search.maven.org/#browse%7C-1002239589.
Step 2: Copy JARs
- Copy to your project's WEB-INF/lib directory
Step 3: Use JSTL tags in .jsp file
- Include the following tags in yours jsp's:
- <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
- <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
- <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
Different Groups in JSTL tag library
- Core Tags
- Formatting Tags
- XML Tags => provides ways to interact with XML data like parsing XML, transforming XML data etc.
- JSTL Functions => most are common string manipulation functions
Benefits of usibg JSTL ?
No comments:
Post a Comment