Share on Google+Share on Google+


In this lesson we will learn about the various tags available in JSP with suitable examples. In JSP tags can be devided into 4 different types.



In this lesson we will learn about the various tags available in JSP with suitable examples. In JSP tags can be devided into 4 different types. These are:
  1. Directives
    In the directives we can import packages, define error handling pages or the session information of the JSP page.
  2. Declarations
    This tag is used for defining the functions and variables to be used in the JSP.
  3. Scriplets
    In this tag we can insert any amount of valid java code and these codes are placed in _jspService method by the JSP engine.
  4. Expressions
    We can use this tag to output any data on the generated page. These data are automatically converted to string and printed on the output stream.
Now we will examine each tags in details with examples. DIRECTIVES

Syntax of JSP directives is:

<%@directive attribute="value" %>

Where directive may be:

  1. page: page is used to provide the information about it.
    Example: <%@page language="java" %> 
  2. include: include is used to include a file in the JSP page.
    Example: <%@ include file="/header.jsp" %> 
  3. taglib: taglib is used to use the custom tags in the JSP pages (custom tags allows us to defined our own tags).
    Example: <%@ taglib uri="tlds/taglib.tld" prefix="mytag" %> 

and attribute may be:

  1. language="java"
    This tells the server that the page is using the java language. Current JSP specification supports only java language.
    Example: <%@page language="java" %> 
  2. extends="mypackage.myclass"
    This attribute is used when we want to extend any class. We can use comma(,) to import more than one packages.
    Example: <%@page language="java" import="java.sql.*,mypackage.myclass" %> 
  3. session="true"
    When this value is true session data is available to the JSP page otherwise not. By default this value is true.
    Example: <%@page language="java" session="true" %> 
  4. errorPage="error.jsp"
    errorPage is used to handle the un-handled exceptions in the page.
    Example: <%@page language="java" session="true" errorPage="error.jsp"  %> 
  5. contentType="text/html;charset=ISO-8859-1"
    Use this attribute to set the mime type and character set of the JSP.
    Example: <%@page language="java" session="true" contentType="text/html;charset=ISO-8859-1"  %> 

If you enjoyed this post then why not add us on Google+? Add us to your Circles

Liked it!  Share this Tutorial

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 13, 2008

Related Tutorials

Ask Questions?    Discuss: INTRODUCTION TO JSP TAGS   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
April 13, 2011
need sample code

want jsp code for generating auto numbers plz anybody help me..
diwakar singh
April 25, 2011

i want to get all in info about core java, jsp, advance java with its examples.
vinod k
June 7, 2011

very good
N.Prakash Sysarc Informatix pvt ltd.
July 8, 2011

the jsp tags which was given above was very neat and crispy.. Thank you.
October 25, 2011

where are the remaining tags types and exaples
M.Nagarjuna reddy
November 9, 2011
show one example how to develop custom tag in jsp

this material is good ...try to give more information regarding the topic...
dhameliya sanjaykumar kanjibhai
November 13, 2011

jsp tag
yelluchuri vijaya babu
November 29, 2011
Page loading problem

the bottom previous,index and next links are not accessible to their corresponding links.please check it.it moves to the same page.top page links are working but bottom links are not working.
Rahul R Gosavi
April 23, 2012

easily got the concept
Rahul R Gosavi
April 23, 2012

easily got the concept
May 9, 2012
jsp tags

why do we use tags in jsp???
Avik Betal
July 8, 2012
Gio graphical Information system

Can JSP be used to display geo-spetial objects like, any .shp file
neha jaswal
November 3, 2012

* study
November 6, 2012
jsp instruction

how to operate jsp
Ravilla siva
December 24, 2012
i want C meterial

plz.i want c meterial.all basics and full meterials