Java Reference
In-Depth Information
Statement Type
Purpose
Tag Example
<% error(); %>
<% ctr = ctr + 1; %>
scriptlet
Perform Java snippets or statements
<%= new Date() %>
<%= 1+1 %>
expression
Expression evaluated, converted to String,
displayed on page
<%! private void error() {
System.out.println("Error!"); } %>
declaration
Define Java methods and variables
<%@ page import = "java.util.*" %>
directive
Define JSP wide
information
Although these tags work, they are not XML-compatible and don't follow the same format as other JSP tags.
Therefore, the following JSP tags are preferred.
Statement Type
Tag Example
<jsp:scriptlet> error(); </jsp:scriptlet>
scriptlet
<jsp:expression> 1+1 </jsp:expression>
expression
<jsp:declaration> private void error() {
System.out.println("Error!"); } </jsp:declaration>
declaration
<jsp:directive.page import = "java.io.*"/>
directive
A JSPs' appearance can also be easily enhanced by using the Design views' GUI to drag and drop components,
as well as, specify formatting options (rather than typing HTML commands, as we did with servlets). Aren't JSPs so
much easier than servlets? In addition, JSPs can be called from Web pages (just like servlets), and JSPs can call servlets
(just like Web pages). So, JSPs are just as powerful as servlets but as easy to build as Web pages.
Of course, now the bad news: JSPs aren't that simple. In actuality, the application server converts a JSP into
a servlet. Within the server are containers that are responsible for handling various pieces of the server-side
application. (A container is simply a subsection/piece of the application server software.) For example, there is a
container that manages all servlets and JSPs. Part of this container's responsibility is to take all the HTML and Java
source code in a JSP and create a servlet. When a JSP is accessed for the first time, it will often take a long time to be
displayed because the container translates the JSP into a servlet, compiles the servlet source code, and then runs the
generated class file.
Tutorial: JSP Standard Tag Library (JSTL)
There are actually many JSP tags and programmers can even create tags. Tags are better than Java scripts because of
their simpler syntax. In addition, using tags makes the code more standard. One very popular set of tags, JSTL tags,
provide the function of many commonly coded Java scripts. For example, instead of coding the Java for statement in a
scriptlet, the JSTL forEach tag can be used. As an example, we will change the HowdyJSP to use the forEach tag.
JSTL comes with RAD. As a matter of fact, in the Design view palette, there is a tray for JSP Tags that includes
JSTL tags.
1.
In the JSP Tags tray, scroll down the options and click on the For Loop to select it.
2.
In the Design view, click on the line after the second scriptlet to insert the forEach tag.
 
 
Search WWH ::




Custom Search