SET AS HOME PAGE

ADD TO FAVORITES / BOOKMARK THIS WEBSITE (More Details)

Introduction

Servlet

Jsp

Security

Enterprise Beans

Contact Us


Introduction to JavaServer Pages - JSP (Continue...)

 Introduction

JavaServer Pages — JSP is a Java based technology that is used to develop dynamic web sites. With JSP, web designers and developers can quickly incorporate dynamic elements into web pages using embedded Java and markup tags. These tags provide the HTML designer with a way to access data and business logic stored inside Java objects.


 JSP Implicit Objects

The following table lists the various implicit objects, with their class, and description:

Implicit Object Class Description
Application javax.servlet.ServletContext The application object defines a Web application. Usually, it is the application in the current Web context.
Config javax.Servlet.ServletConfig Represents the object of a ServletConfig class. .
exception java.lang.Throwable Represents the Throwable exception, in a JSP page. .
out javax.servlet.jsp.JspWriter Represents an object of JspWriter to send response to the client. JspWriter extends the PrintWriter class and is used by JSP pages to send client responses. .
page java.lang.Object Represents the current instance of the JSP page that in turn is used to refer to the current instance of the generated servlet. .
session javax.servlet.http.HttpSession Represents a session object of HttpSession interface. .
response javax.servlet.http.HttpServletResponse Represents a response object of HttpServletResponse that is used to send a HTML output to the client. .
request javax.servlet.http.HttpServletRequest Represents a request object of HttpServletRequest. It is used to retrieve data submitted along with a request. .
pageContext javax.servlet.jsp.PageContext Represents the page context for a JSP page. .
Example:
The syntax to set the user name in the session is:
session.setAttribute( "userName", name );
The syntax to retrieve the value of the username from the session is:
session.getAttribute( "userName", name );
 JSP Actions

The syntax to use a JSP action in a JSP page is:
<jsp:attribute>
The following table lists the various JSP action tags along with their description, attribute supported, and description of attributes:

JSP Action Description Attribute Description of Attributes
<jsp:useBean> Invokes and searches for an existing bean. id

Uniquely identifies the instance of the bean.
class

Identifies the class from which the bean objects are to be implemented.
scope

Defines the scope of the bean.
beanName

Defines the referential name for the bean.
<jsp:getProperty>Retrieves the property of a bean. name

Defines the name for the bean.
property

Defines the property from which the values are to be retrieved.
<jsp:setProperty>Used to set the property of a bean. name

Specifies a name for the bean.
property

Defines the property for which values are to be set.
value

Defines an explicit value for the bean property.
param

Defines the name of the request parameter to be used.
<jsp:forward>Used to forward a request to a target page. page

Specifies the URL of the target page.
<jsp:include>Includes a file in the current JSP page. page

Specifies the URL of the resource to be included.
flush

Specifies whether the buffer should be flushed or not. The flush value can be either true or false.
<jsp:param>Define a parameter to be passed to an included or forwarded page. name

Defines the name of the reference parameter.
value

Defines the value of the specified parameter.
<jsp:plugin>Executes a Java applets or a JavaBean. type

Defines the type of plug-in to be included.
code

Defines the name of the class to be executed by the plug-in.
codebase

Defines the path of the code.
Example:
<jsp:include page="toolbar.jsp"> </jsp:include>
 Classes of JSP API

Some of the classes defined in the javax.servlet.jsp package are:
  • ErrorData
  • JspWriter
  • PageContext

The ErrorData Class
You need to set the value of the page directive, isErrorPage to be true to indicate that a page is an error page.


The JspWriter Class
The JspWriter class is used to write action and template data in a JSP page. The object of JspWriter class is referenced by the implicit variable, out.


The PageContext Class
The PageContext class provides context information when the JSP technology is used in the servlet environment. The PageContext class extends the JspContext class.


 Click for Next Topic
<- PREVIOUSNEXT ->