Enlist types of JSP tags?

devquora
devquora

Posted On: Mar 22, 2020

 

Tags are an important part of JSP. There are 4 main types of JSP tags,

Directive tag: This type of tag is used to import packages into the current JSP application. The other use for this directive is to define error handling pages and for session information.

Syntax

 
<%@ directive attribute="value" %> 

The three types of directive tags are,

  • <%@page...%> - it defines page-dependent attributes.
  • <%@include...%> - it includes a file.
  • <%@taglib...%> - it declares a tag library to be used on the page.

Example

<%@page language="java" session="true" %> 
<%@ include file="/title.jsp"%> 

Declaration tag: This tag is used to declare variables or methods to be used in the Java code of the JSP.

Syntax

<%! declaration; %> 

Example

<%! int k = 0; %> 

Scriptlet tag: This tag contains the actual java code like java declaration, methods, expressions, etc.

Syntax

<% java code %> 

Example

<% out.print(“an example of scriptlet tag”); %> 

Expression tag: The expression tag contains an expression that needs to be evaluated. It can contain any expression that is valid in Java code.

Syntax

<%= expression %> 

Example

<%= (new java.util.Date()).toLocaleString()%> 

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    JSP Interview Questions

    Explain What is JSP?

    JSP, expanded as Java Server Pages is a Java-based technology to create dynamic web pages. Released in 1999 by Sun Microsystems, JSP is based on technologies such as HTML, SOAP, XML, etc...

    JSP Interview Questions

    What is the el in JSP?

    The EL (Expression Language) in the JSP is used to access the data stored in the JavaBeans along with implicit objects like requests, sessions, etc...