The HTTP (Hypertext Transfer Protocol) was designed for transferring files over the World Wide Web (WWW). HTTP uses simple communication model. A client who uses browser to send request for some files, the server responds the request. For example, the client request username and the server send response the username to client. After completing the response, the communication connection is complete. And then the client request another resource, the server has no way of distinguishing it from any other client. So HTTP is called Stateless protocol.
Session Tracking:
1). Hidden Form Fields.
2). URL rewriting
3). Cookies
4). HTTP session API
Example:
Letus go for understanding the use of session.
Consider three files A.jsp and B.jsp and Result.jsp
A.jsp file have one textbox to get FirstName as input and OK button.
Screen Shot below
B.jsp file have one textbox to get Lastname as input and OK button.
Implicit object means pre-defined object. Jsp provide some implicit object. Already jsp developer has created some object for later use. This object is called implicit object.
What is oops?
Object Oriented Programming is main feature of java. In java every task is performed within the method. The method is defined within the class. To call this method, using object. So we must create object of this class and use new operator to create object. Using object, we call method. So it is called object oriented programming.
A). Create class
B). Create method
C). Create object in main class
D). Using object, call the method.
But java developer feels that some object are needed often. So they created class and created object themselves. So we don’t need to create object separately. We just use object name.method name. Here we keep it in mind which method is used for which purpose.
Note:
How to call pre defined method?
All predefined method are included within the class. And that class also is included into the package. So we import the package and create the object of the class. Using created object, we can call the method.
For example, we want to get the time. First we import java.util package. Because the method getHours() is included in java.util package. So we include java.util package and create the object for Date class.
Java.util.Date
getHours()
import java.util.*;
class Example
{
public void display()
{
Date d=new Date();
System.out.println(d.getHours());
}
}
class Examplemain
{
public static void main(String args[])
{
Example e=new Example();
e.display();
}
}
Here we import java.util and create object for Date class and using object of the Date class to call the getHours() method.
But if we use predefined boject, there is no need to create object to call method.
They defined eight pre defined object.
1). request
2). response
3). session
4). out
5). application
6). config
7). pageContext
8). page
Implicit Object
type
request
javax.servlet.http.HttpServletRequest(For Http)
javax.servlet.ServletRequest(Not Http)
It is used to retrieve data submitted along with a request.
Implicit Object
type
response
javax.servlet.http.HttpServletResponse(For Http)
javax.servlet.ServletResponse(Not Http)
It is used to send an HTML output to the client.
Implicit Object
type
session
javax.servlet.http.HttpSession
·session object is associated with request object.
Implicit Object
type
out
javax.servlet.jsp.JspWriter
·Used for writing data to the output buffer
·Buffer size can be adjusted or can be turned off using buffer attribute in page directive
·out object is used in scriptlets
Implicit Object
type
exception
java.lang.Throwable
·refer to the runtime exception
Implicit Object
type
page
java.lang.Object
Represent the this object for the current instance of the jsp
Implicit Object
type
pageContext
Javax.servlet.jsp.PageContext
·represent the PageContext object for this page.
Implicit Object
type
config
Javax.servlet.ServletConfig
·Contain servlet configuration data
Implicit Object
type
application
javax.servlet.ServletContext
·It is used to share information among all usrs of a currently active application
From Previous post, we have understood how to create custom body tag. From this post, we will learn how to create custom tag with body and attributes. If we create attribute, we will add attribute name when we create tag Handler class.
From Previous post, we have understood how to create custom body tag. From this post, we will learn how to create custom tag with body and attributes. If we create attribute, we will add attribute name when we create tag Handler class.
The output is the body content is converted into the UpperCase.
We specify custom tag contain body when we are creating TLD file. When we create TLD file, we specify < body-content > element of the TLD as JSP. When we create Custom Tag .we specify < body-content > as empty. Now we are going to create custom tag with body so we specify < body-content > as JSP to indicate that container evaluate the body content of the tag.
Note:
We specify < body-content > as tagdependent, the jsp container should not evaluate the body of the tag but instead pass it to the tag handler for evaluation.
No need to include coding into the TLD file. The content of the TLD file will be automatically included into the TLD file when we create Tag handler Class.
Step 3:
Create Tag Handler Class named as GoodMorning.
Select BodyTagSupport because we are going to create Custom tag with body.
Note: we have selected Body Content as JSP.
Step 4:
Create jsp file named as good.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 >
< %@taglib uri="/WEB-INF/tlds/good" prefix="good" % >
< html >
< head >
< title > JSP good Page < /title >
< /head >
< body >
< h1 > Hello World! < /h1 >
< good:GoodMorning >
sureshkumar
< /good:GoodMorning >
< /body >
< /html >
Custom tag contains many attributes. For every attribute of custom tag, we need to create a property. We use getXXX() and setXXX() methods to access and set the value for the property in the Tag handler Class.
Example:
< hello:Hello username=”sureshkumar”/ >
Here, username is a property of the custom tag. And the value of the username is sureshkumar.
Let us go to create custom tag with attributes.
We use TagSupport class to implement custom tag with attributes.
We include username attributes into the Tag Handler Class.
We also setXXX() for username as setUsername().
We also getXXX() for username as getUsername().
To define a custom tag with attribute in a TLD file, we need to specify that the custom tags contain attributes in the attribute elements of the TLD file. The attribute elemtn contains the following sub-elements.
name: specify the name of the attribute.
required: specify that the attribute is required or optional. If you specify required as true,the attribute value must be present in the JSP page.
rtexprvalue:specify that run-time expression, for example JSP expression can be used for this attribute. Possible values include true,false,yes,no.
Procedure:
Step 1:
Create project (Already we have create project named as CustomTagProject)
You want to know how to create Project to develop the jsp page.
Refer Following Link