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.
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 :
Defines the scripting language of the JSP page
Defines the extended parent class of the JSP
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
|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
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 :
|uri||Locates the TLD file of a custom tag.|
|prefix||Defines a prefix string to be used for
distinguishing a custom tag instance
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 OBJECTSJSP Implicit Objects are:
?Pre-defined variables that can be included in JSP expressions and scriptlets.
?Implemented from servlet classes and interfaces.
Out JSP writer
Config Sevlet Config
Page ObjectPageContext Page Context => is responsible
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?);
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:
Where ?Name? is the form element.
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 belongs to class SevletContext and used to
maintain certain information throughout the scope of Application.
This object is of class pageContext and is utilized to access the other implicit objects.Display "Hello JSP" using Jsp expression
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.