This section is about JSP & it's page components, their usage and syntax.
This section is about JSP & it's page components, their usage and syntax.What is JSP ?
JSP Stands for "Java Server Pages". Using "JSP" we can use both, static HTML with dynamically-generated HTML. Web pages created using CGI programs are mostly static , dynamic part is limited to a few small locations. But using CGI and servlet , you can generate entire page through one program. Using JSP, you can built two parts separately.1. DIRECTIVES
A directive element in a JSP page provides global information about a particular JSP page and is of three types:
The syntax for defining a directive is : <%@ directive attribute=?value? %>
Defines attributes that notify the Web container about the general settings of a JSP page.
The syntax of the page directive is : <%@ page attribute_list %>
The following table describe the attribute supported by the page directive :
Attribute name | Description |
Language |
Defines the scripting language of the JSP page |
extends |
Defines the extended parent class of the JSP generated servlet |
imports |
Imports the list of packages, classes, or interfaces into the generated servlet. |
session | Specifies 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 attribute is true. |
buffer | Specifies the size of the out buffer. If size
is set to none, no buffering is performed. The default value of buffer size is 8 KB. |
autoFlush | Specifies that the out buffer be
flushed automatically if the value is set to true. If the value is set to false, an exception is raised when the buffer is full. The default value of autoFlush attribute is true. |
isThreadSafe | Specifies whether a JSP page is thread safe or not. |
errorPage | Specifies that any un-handled
exception generated will be directed to the URL. |
isErrorPage | Specifies that the current JSP page is an
error page, if the attribute value is set to true. The default value of isErrorPage attribute is false |
contentType | Defines the Multipurpose Internal Mail Extension
(MIME) type for a response. The default value of the contentType attribute is text/html. |
Specifies the names of the files to be inserted during the compilation of the
JSP page The included file can be an HTML file, a JSP file, a text file, or a
code file written in the Java programming language. Creates the contents of the included files as part of the JSP page.
The syntax of the include directive is: <%@
include file = ?relativeURL? %>
Imports a custom tag into the current JSP page.
Associates itself with a URI to uniquely identify a custom tag.
Associates a tag prefix string that distinguishes a custom tag with the other tag library used in a JSP page.
The following table describe the attribute of the taglib directive :
Attribute Name | Description |
uri | Locates the TLD file of a custom tag. |
prefix | Defines a prefix string to be used for distinguishing a custom tag instance |
Syntax:
This inclusion of file is dynamic and the specified file is included in the JSP file at run-time i.e. out put of the included file is inserted into the JSP file.
Forward : <jsp:forward page=?<filename>? />This will redirect to the different page without notifying browser.
6. IMPLICIT OBJECTS
? Pre-defined variables that can be included in JSP expressions and scriptlets.
? Implemented from servlet classes and interfaces.
OBJECT CLASS
Out JSP writer
Request HttpServletRequest
Response HttpServletRespose
Session HttpSession
Application ServletContext
Config Sevlet Config
Page Object
PageContext Page Context => is responsibleOut:
This object is instantiated implicitly from JSP Writer
class and can be used for displaying anything within delimiters.
For e.g. out.println(?Hi Buddy?);
Request:
It is also an implicit object of class HttpServletRequest
class and using this object request parameters can be accessed.
For e.g. in case of retrieval of parameters from last form
is as follows:
request.getParameters(?Name?);
Where ?Name? is the form element.
Response:
It is also an implicit object of class HttpServletResponse
class and using this object response(sent back to browser) parameters can be
modified or set.
For e.g. in case of modifying the HTTP headers you can use
this object.
Response.setBufferSize(?50?);
Session:
session.setValue(?Name?,?Jakes?);
session.setValue(?Age?,?22?);
Application:
This object belongs to class SevletContext and used to
maintain certain information throughout the scope of Application.
Application.setValue(?servername?,?www.myserver.com?);
PageContext:
This object is of class pageContext and is utilized to access the other implicit objects.