JSP defines six types of tag elements:

Action: Follows the XML (eXtended Markup Language) format and always begins with <jsp:some action/>. It provides a way to add more functionality to JSP, such as finding or instantiating (creating) a JavaBean for use later. You see one example of an action tag in line 12 of the code in Listing 1-1.

Directive: A message to the Web container describing page properties, specifying tag libraries, or substituting text or code at translation time. The form is <%@ the directive %>. Listing 1-1 has directives on lines 1, 3, and 5.

Declaration: Declares one or more Java variables or methods that you can use later in your page. The tag has this form <%! declaration %>.

Expression: Defines a Java expression that is evaluated to a String. Its form is <%= expression %>.

Scriptlet: Inserts Java code into the page to perform some function not available with the other tag elements. Its form is <% java code %>.

Comment: A brief explanation of a line or lines of code by the developer. Comments have the form <%– the comment –%>. Lines 2 and 4 in Listing 1-1 are examples of comments.

Listing 1-1 Sample JSP Page
1 <%@ page contentType=”text/html;charset=UTF-
8”language=”java” %>
2 <%– JSTL tag libs –%>
3 <%@ taglib prefix=”fmt” uri=”/WEB-INF/fmt.tld” %>
4 <%– Struts provided Taglibs –%>
5 <%@ taglib uri=”/WEB-INF/struts-html-el.tld”
prefix=”html” %>
6 <html:html locale=”true”/>
7 <head>
8 <fmt:setBundle basename=”ApplicationResources” />
9 <title><fmt:message key=”loggedin.title”/></title>
10 </head>
11 <body>
12 <jsp:useBean id=”polBean”
class=”com.othenos.purchasing.struts.POListBean”/>
13 <H2>
14 <fmt:message key=”loggedin.msg”>
15 <fmt:param value=’${polBean.userName}’ />
16 </fmt:message>
17 </H2>
18 </body>
19 </html>