JSP Elements

JSP elements describe you the various types of tags in JSP.

JSP Elements

JSP Elements

In this section we will learn about the JSP elements that we can use on a JSP page. This section will describe you all types of JSP elements that we can use on JSP page.

JSP elements are called the JSP tags on JSP page. On the JSP page mainly three groups of JSP elements are used :

  • JSP Scripting Elements
  • JSP Directive Elements
  • JSP Standard Action Elements

JSP Scripting Elements

JSP Scripting Elements are used for writing the Java Code inside the JSP page. There are different types of scripting elements these elements are used for various purposes. Following are the scripting elements :

  • JSP Scriptlet element/tag : A scriptlet tag is denoted by the special characters <%  %>. The special characters '<%' specifies the starting of the scriptlet tag and '%>' specifies end of scriptlet. On the JSP page Java Code is written inside it.
     
  •  JSP Declaration element/tag : The declaration tag is denoted by the special characters <%!  %>. The special character '<%!' specifies the start of the declaration and '%>' specifies the end of the declaration. Declaration element is used to declare the fields, methods to use inside the JSP page. These declaration element helps developer to declare fields, methods like in Servlet how they can declare.
     
  • JSP Expression element/tag : Then expression tag is denoted by the special characters <%=  %>. The special character '<%= specifies the starting of the expression and '%>' specifies the end of the expression. The expression tag is used to set the output. The expression is used like the 'out' implicit object in JSP.

JSP Directive Elements

Directive elements in JSP provides the special information to the JSP engine. It gives the information about the JSP page. Each JSP page goes through the two phases i.e. translation phase and request time phase. At the translation phase JSP page is translated into a Servlet. The JSP engine translates the JSP page into a Servlet, directive elements are handled at the translation time. These directives are translated to the Servlet only for once, until there is no changes made to the directive elements in the Servlet.

JSP Directive Elements can be declared within the following special characters '<%@   %>'. Syntax for using directive in the JSP page is as follows :

<%@ directiveName attr1="value1" attr2="value2" %>

JSP Standard Action Elements

JSP Action Elements are used to take action on the basis of some information. These action elements can create, modify or use the other objects. Action elements are coded with the strict syntax they are used to apply the built-in functionality. Action elements are represented as <jsp:tagName>  </jsp:tagName>. Code is written inside these tags, the <jsp:tagName> specifies the starting of the action tag where as the action tag is ends with </jsp:tagName>. When you are not required to defined the body of the tag you may end up the action tag by <jsp:tagName/>

Miscellaneous

JSP Comment Elements

JSP comment elements are used to hide your code from the "view page source". However, you can use HTML comment tags in JSP page but, when user of your website will choose the "view page source" then they can see your commented code. The JSP comment is denoted by the special character <%--  --%>. The special character '<%--' specifies the opening comment element and the special character '--%>' specifies the end of the comment tag.

HTML comment tag is denoted by the special characters '<!--  -->' where, '<!--' specifies the start tag and '-->' specifies the end tag.