2. Why use JSTL?
Advantage of JSTL
- Scriptlets (
Java codes withinJSP ) are complex and are extremely hard to be maintained. Unlike scriptlets, JSTL makes our JSP readable and maintainable. - HTML programmer may find it hard to modify the JSP with the scriptlets as he or she may not have the
Java programming knowledge. However, if we are using JSTL to replace our scriptlets, HTML programmer can easily understand on what’s going on in the JSP as JSTL is in the form of XML tags similar to the normal HTML tags. - JSTL has been standardized and is reusable tags.
- The name of each tag in JSTL is self-explanatory and is easy to understand.
- JSTL requires less code compared to scriptlets.
Shortcomings of JSTL
- Scriptlets provide you with greater flexibility. As scriptlets is simply a Java codes, you can do anything that you want as you normally do with a Java programming. On the other hand, JSTL is a very specific and each tag has its own purposes.
JSTL Tutorial
Until now, you should have known the basic of the JSTL theoretically. Let’s move on to real JSTL practice. Start your NetBeans.
Create New Project
Let’s first us create new project for this tutorial. After Netbeans has already been started, choose File and New Project…
A wizard dialog will show up, choose Web on the left panel and choose Web Application on the right panel. Then click Next to continue.
In the step 2, we are required to fill in our project’s information details. Use self-explanatory name for the project name. Ok, let’s call it JstlDemo. We can keep the rest as default. Then click Finish.
At this point, our web application is ready. File called index.jsp will be automatically created for us.
Preparing the Library
JSTL requires 2 jars; jstl.jar and standard.jar. These two files are not included in our default library. We need to add these libraries to our project.
On the left projects tab panel, we can see a folder named Libraries. Right click on this folder and Add Library…
After this one, we will see list of available libraries. Choose JSTL 1.1 and Add Library.
If you carefully look at the index.jsp, it contains the JSTL tag but it is commented.
<%--
<%@taglib uri="http://java.sun.com/jsp/jstl/core " prefix="c"%>
--%>
You may try to uncomment it to test whether you have correctly imported the JSTL libraries.
Java may be the main choice for enterprise development now, but it’s days are numbered as the only stalwart option to go with.
ReplyDeleteLet’s face it, many of these so called “enterprise applications” could easily have been written much faster and with less overhead using technologies like Python, PHP, et al.
open source training