Tuesday, October 5, 2010

JSP elements of jsp


JSP- Java Server Pages: Elements of jsp


Introduction:

A JSP page consists of various components. We use this components to create jsp application. There are three components in jsp of a jsp page:

1). JSP directives

2). JSP scripting

3). JSP actions

JSP Directives:

A directive element in a jsp page provides global information aboud a particular jsp page.
There are three types of directives.

1). Page directives

2). Taglib directives

3). Include directives

We include directive between <@ and %&gt. A directive have more than one attribute.

Syntax:

< % directive attribute=”value” % >


Page Directive:

The page directive defines attributes that tell the web container about the general setting of a jsp page. We specify different attributes with the page directive.

<% page attribute_list %>



Attribute name
              Description
language
Specify the scripting language of the jsp page


extends
Specify the parent class that the jsp generated servlet extends.
import
Import the list of packages, classes, or interfaces into the generated servlet.


session
Specify if the generated servlet can access the session or not. An implicit object, session, is generated if the value is set to true. The default value of session is true.


buffer
Specify the size of the out buffer. If size is set to none, no buffering is performed. The default value of buffer size is 8kb.


autoflush
Specifies the out buffer is flushed automatically if the value is set to true. If the value is set to false, an exception is thrown when the buffer is full. The default value of autoflush attribute is true.



isThreadSafe

This attribute tells the jsp engine that this page can service more than one request at a time. By default, this value is true. If we set to false, the SindleThreadModel is used.

errorPage

This attribute represents the relative URL to the JSP errorPage. The default is false.



isErrorPage

Specify that the current JSP page is an error page, if the attribute value is set to true. The default value is false



contentType


Specify the MIME (multipurpose Internal Mail Extension) for a response. The default value is text/html.





2). Taglib directive

The taglib directive imports a custom tag into the current jsp page. Custom tag is user-defined tag, which is used to perform repetitive tasks in jsp page. The Tag Library Descriptor (TLD) file defines the functionality of a custom tag.



<%@ taglib uri=”tag lib uri” prefix=”specify prefix” % >


Attribute
Description


uri


Locates the TLD file of a custom tag


Prefix


Defines a prefix string to be used for distinguish a custom tag instance.

Type of tag extension


1). Custom tag without body

2). Custom tag with body

3). Custom tag with nested


3). Include directive

The include directive is used to insert text and code at JSP translation time.

< % include file=”URLName” % >

Example for include directive


home.html


< !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >

< html >
< head >
< title > Example for include directive < /title >
< /head >
< body >
sureshkumar from home.html
< /body >
< /html >


includeExam.jsp

< %@page contentType="text/html" pageEncoding="UTF-8"% >

< !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
http://www.w3.org/TR/html4/loose.dtd >
< %@include file="home.html" % >
< html >
< head >
< meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
< title > JSP Page < /title >
< /head >
< body >
< h1 > Hello World! < /h1 >
< /body >
< /html >


No comments:

Post a Comment