JSP tags are an essential part of Java Server Pages, a server-side technology. Tags in JSP create a container for Java code, insulating and providing separation of dynamic content from static design elements in your site. Although many resemble those used in Hyper Text Markup Language – HTML - JSP tags are not part of a scripting language. Instead, tags in JSP are just one element in a technology focused on generating dynamic Web content. JSP tags determine how the code within them will behave. A list of common JSP tags can be a good reference to ensure you choose and use tags correctly.
JSP Declaration Tags
Declaration tags in JSP function as identification containers for the functions, methods and variables in JSP pages. Because these tags identify rather than generate output, you will most often find declaration tags working in combination with expression or scriptlet tags. Syntax options include the simple "<%! jsp declaration %>" and the XML alternative "jsp:declaration…."
Video of the Day
JSP Expression Tags
Expression tags signal JSP to convert a Java statement – also called an expression – into a string and display the output. Syntax options include the simple "<%= Java statement %>" and the XML alternative "jsp:expression…."
JSP Directive Tags
Directives – or message tags – are instructional tags that contain two parts: type and attribute. Type can be "page," which gives page-specific processing directions, "Include," which provides specific file names or "Tag Library," which identifies the tag library you want to use on the current page. Syntax options include the simple "<%@ dir-type dir-attr %> and the XML alternative "<jsp:directive.dir_type dir_attr />."
JSP Scriptlet Tags
Scriptlet tags allow you to embed any valid Java source code in JSP server pages. The code within the tags executes in consecutive order on the server side and is available for client access through a Web browser. Syntax options include the simple "<% Java code %> and the XML alternative "jsp:scriptlet Java code ."
JSP Flow Control Tags
Flow control tags function the same as – and are an alternative to – scriptlets. Unlike scriptlets, however, flow control tags allow you to control the order in which statements run. The conditional tags "if" and "choose" and the iterator tags "forEach" and "forTokens" are all examples of JSP flow control tags. The syntax framework for each includes <c:tag_type tag_attribute> Java code . For example, when you use an "if" statement, the correct syntax is <c: if test= "$test parameters"> Java code </c: if > where test= is the type and "$test parameters" identifies tag attributes.
JSP Action Tags
Action tags can tell JSP to transfer control between pages, set or get properties, facilitate browser independent support for Java applets and make it possible to use server-side JavaBeans. Of the many available action tags, the most common are the include directive, the forward tag, which transfers control to a dynamic or static URL and the useBean tag, which allows a JSP to create or receive an instance of a reusable software component that works with Java called a JavaBean. The only syntax option for an action tag is the XML version: "jsp:useBean Java body ."
JSP Comment Tags
Comment tags are for "information only" and do not appear on JSP pages. Use them for clarification or documentation and view them by right clicking on a Web page and accessing the "view source" option. The only syntax option for a comment tag is the simple version: <%/ comments go here />.