SlideShare ist ein Scribd-Unternehmen logo
1 von 12
Downloaden Sie, um offline zu lesen
Let’s Move on:


        JSP Objects
                 An overview




                               Biswabrata Banerjee
JSP Objects
Built-in JSP Objects and Their Implementation Classes:

      JSP Object                  Implementation Class

      Request                    HttpServletRequest
      response                   HttpServletResponse
      out                        JspWriter
      session                    HttpSession
      application                ServletContext
      pageContext                PageContext
      config                     ServletConfig
      page                       Object
      exception                  Throwable



                                                         Biswabrata Banerjee
Cont ‘d …               JSP Objects




      These objects are implicitly created at the beginning of a page when
your JSP is invoked, and they directly reference objects in the underlying
servlet.
      They are always available to scriptlets and expressions.




                                                              Biswabrata Banerjee
a brief description
The request Object
The request object represents the current request from the browser and is a subclass of the
ServletRequest class. For most current implementations of JSP, the request object is an
instance of HttpServletRequest.

The response Object
Like the request object, the response object is usually a subclass of the HTTP-specific version
of ServletResponse. In other words, it is usually an instance of HttpServletResponse.

The out Object
The out object is responsible for writing responses back to the browser and is an instance of the
JspWriter class.

The session Object
The session object is an instance of HttpSession. Because there is an obvious dependence on
HTTP, this object is available only if your JSPs use HTTP.

The application Object
The application object is an instance of the ServletContext object. The names "application"
and "ServletContext" don't seem very similar, but if you recall what the ServletContext class
does, you'll see that it manages data at the application level.

                                                                               Biswabrata Banerjee
Cont ‘d…                                                        a brief description

The pageContext Object
          The pageContext object is an instance of the PageContext class. Many of the
items available through built-in variables are also available through the pageContext
object.

The config Object
           The config object gives you access to configuration information for your JSP and
is an instance of the ServletConfig class.

The page Object
         The page object is rather peculiar because it is a reference to the current JSP. In
other words, it's like an alias for the this keyword in Java.

The exception Object
          When you create an error page to deal with exceptions that occur during normal
JSP processing, you might need access to the exception that caused the error page to be
invoked. You can access that exception through the exception object.


                                                                            Biswabrata Banerjee
Request Object
      JSP Request Object

       Request Object in JSP is used to get the values that the client passes to the
web server during an HTTP request. The request object is used to take the value
from the client’s web browser and pass it to the server. This is performed using an
HTTP request such as: headers, cookies or arguments.
       The class or the interface name of the object request is
http.httpservletrequest.
       The object request is written: Javax.servlet.http.httpservletrequest.
Request Object

Methods of request Object:    There are numerous methods available
                              for request Object. Some of them are:

          getCookies()
          getHeader(String name)
          getHeaderNames()
          getAttribute(String name)
          getAttributeNames()
          getMethod()
          getParameter(String name)
          getParameterNames()
          getParameterValues(String name)
          getQueryString()
          getRequestURI()
          getServletPath()
          setAttribute(String,Object)
          removeAttribute(String)
Response Object
       JSP Response Object

       The response object denotes the HTTP Response data. The result or the information of
a request is denoted with this object. The response object handles the output of the client.
This contrasts with the request object. The class or the interface name of the response object
is http.HttpServletResponse.

      The response object is written as : Javax.servlet.http.httpservletresponse.

      The response object is generally used by cookies. The response object is also used
with HTTP Headers.
Response Object
  Methods of response Object: There are numerous methods
available for response object. Some of them are:

           setContentType()
           addCookie(Cookie cookie)
           addHeader(String name, String value)
           containsHeader(String name)
           setHeader(String name, String value)
           sendRedirect(String)
           sendError(int status_code)
Session Object
  JSP Session Object

      Session Object denotes the data associated with a specific session of user. The
class or the interface name of the object session is http.HttpSession.
      The object session is written as: Javax.servlet.http.httpsession.
      The previous two objects, request and response, are used to pass information
from web browser to server and from server to web browser respectively.The Session
object provides the connection or association between the client and the server. The
main use of Session Objects is to maintain states when there are multiple page
requests.
      The main feature of session object is to navigate between multiple pages in a
application where variables are stored for the entire user session. The session objects
do not lose the variables and the value remains for the user’ session. The concept of
maintenance of sessions can be performed by cookies or URL rewriting. A detailed
approach of session handling will be discusses in coming sections.
Session Object

Methods of session Object: There are numerous methods available
                           for session object. Some of them are:


           getAttribute(String name)
           getAttributeNames
           isNew()
           getCreationTime
           getId
           invalidate()
           getLastAccessedTime
           getMaxInactiveInterval
           removeAttribute(String name)
           setAttribute(String, object)
Out Object
 JSP out object

      JSP out object denotes the Output stream in the context of page. The class
or the interface name of the object out is jsp.JspWriter.
      The out object is written as: Javax.servlet.jsp.JspWriter
      The object that write to the JSP's output stream is defined by the out object.

      Methods of out Object:         There are numerous methods available for
                                   out Object,some of them are :
               clear
               clearBuffer
               flush
               isAutoFlush
               getBufferSize
               getRemaining
               newLine
               print
               println

Weitere ähnliche Inhalte

Was ist angesagt?

OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...mfrancis
 
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology Ayes Chinmay
 
Hibernate complete Training
Hibernate complete TrainingHibernate complete Training
Hibernate complete Trainingsourabh aggarwal
 
Proxy design pattern (Class Ambassador)
Proxy design pattern (Class Ambassador)Proxy design pattern (Class Ambassador)
Proxy design pattern (Class Ambassador)Sameer Rathoud
 
Hibernate working with criteria- Basic Introduction
Hibernate working with criteria- Basic IntroductionHibernate working with criteria- Basic Introduction
Hibernate working with criteria- Basic IntroductionEr. Gaurav Kumar
 
Entity Persistence with JPA
Entity Persistence with JPAEntity Persistence with JPA
Entity Persistence with JPASubin Sugunan
 
Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805LearningTech
 
Spring 3: What's New
Spring 3: What's NewSpring 3: What's New
Spring 3: What's NewTed Pennings
 
Django workshop : let's make a blog
Django workshop : let's make a blogDjango workshop : let's make a blog
Django workshop : let's make a blogPierre Sudron
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepGuo Albert
 
Polyglot persistence with Spring Data
Polyglot persistence with Spring DataPolyglot persistence with Spring Data
Polyglot persistence with Spring DataCorneil du Plessis
 
Introduction to hibernate
Introduction to hibernateIntroduction to hibernate
Introduction to hibernatehr1383
 

Was ist angesagt? (20)

Ajax
AjaxAjax
Ajax
 
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
 
JPA Best Practices
JPA Best PracticesJPA Best Practices
JPA Best Practices
 
Java persistence api 2.1
Java persistence api 2.1Java persistence api 2.1
Java persistence api 2.1
 
Deployment
DeploymentDeployment
Deployment
 
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
 
Hibernate complete Training
Hibernate complete TrainingHibernate complete Training
Hibernate complete Training
 
Proxy design pattern (Class Ambassador)
Proxy design pattern (Class Ambassador)Proxy design pattern (Class Ambassador)
Proxy design pattern (Class Ambassador)
 
Hibernate working with criteria- Basic Introduction
Hibernate working with criteria- Basic IntroductionHibernate working with criteria- Basic Introduction
Hibernate working with criteria- Basic Introduction
 
Proxy pattern
Proxy patternProxy pattern
Proxy pattern
 
Entity Persistence with JPA
Entity Persistence with JPAEntity Persistence with JPA
Entity Persistence with JPA
 
Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805
 
Proxy design pattern
Proxy design patternProxy design pattern
Proxy design pattern
 
Spring 3: What's New
Spring 3: What's NewSpring 3: What's New
Spring 3: What's New
 
Jquery 2
Jquery 2Jquery 2
Jquery 2
 
Django workshop : let's make a blog
Django workshop : let's make a blogDjango workshop : let's make a blog
Django workshop : let's make a blog
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By Step
 
Web2 - jQuery
Web2 - jQueryWeb2 - jQuery
Web2 - jQuery
 
Polyglot persistence with Spring Data
Polyglot persistence with Spring DataPolyglot persistence with Spring Data
Polyglot persistence with Spring Data
 
Introduction to hibernate
Introduction to hibernateIntroduction to hibernate
Introduction to hibernate
 

Andere mochten auch

Andere mochten auch (7)

Oracle docs rmi applications
Oracle docs rmi applicationsOracle docs rmi applications
Oracle docs rmi applications
 
J2EE jsp_01
J2EE jsp_01J2EE jsp_01
J2EE jsp_01
 
J2ee
J2eeJ2ee
J2ee
 
J2EE day 1
J2EE day 1J2EE day 1
J2EE day 1
 
Chapter2 j2ee
Chapter2 j2eeChapter2 j2ee
Chapter2 j2ee
 
Introduction to Java EE (J2EE)
Introduction to Java EE (J2EE)Introduction to Java EE (J2EE)
Introduction to Java EE (J2EE)
 
Leadership concepts and theories
Leadership concepts and theoriesLeadership concepts and theories
Leadership concepts and theories
 

Ähnlich wie J2EE jsp_03

Implicit objects advance Java
Implicit objects advance JavaImplicit objects advance Java
Implicit objects advance JavaDarshit Metaliya
 
Lap trinh web [Slide jsp]
Lap trinh web [Slide jsp]Lap trinh web [Slide jsp]
Lap trinh web [Slide jsp]Tri Nguyen
 
Request dispacther interface ppt
Request dispacther interface pptRequest dispacther interface ppt
Request dispacther interface pptTaha Malampatti
 
Implicit Objects &Handling.pptx
Implicit Objects &Handling.pptxImplicit Objects &Handling.pptx
Implicit Objects &Handling.pptxKSuvetha1
 
JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)Talha Ocakçı
 
JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESYoga Raja
 
Introduction to JSP
Introduction to JSPIntroduction to JSP
Introduction to JSPGeethu Mohan
 
JSP - Java Server Page
JSP - Java Server PageJSP - Java Server Page
JSP - Java Server PageVipin Yadav
 
3.jsp tutorial
3.jsp tutorial3.jsp tutorial
3.jsp tutorialshiva404
 
Jsp session implicit object
Jsp session implicit objectJsp session implicit object
Jsp session implicit objectchauhankapil
 
Atul & shubha goswami jsp
Atul & shubha goswami jspAtul & shubha goswami jsp
Atul & shubha goswami jspAtul Giri
 
JSP Components and Directives.pdf
JSP Components and Directives.pdfJSP Components and Directives.pdf
JSP Components and Directives.pdfArumugam90
 
Session 31 - Session Management, Best Practices, Design Patterns in Web Apps
Session 31 - Session Management, Best Practices, Design Patterns in Web AppsSession 31 - Session Management, Best Practices, Design Patterns in Web Apps
Session 31 - Session Management, Best Practices, Design Patterns in Web AppsPawanMM
 

Ähnlich wie J2EE jsp_03 (20)

Implicit objects advance Java
Implicit objects advance JavaImplicit objects advance Java
Implicit objects advance Java
 
Lap trinh web [Slide jsp]
Lap trinh web [Slide jsp]Lap trinh web [Slide jsp]
Lap trinh web [Slide jsp]
 
Introduction to JSP.pptx
Introduction to JSP.pptxIntroduction to JSP.pptx
Introduction to JSP.pptx
 
Request dispacther interface ppt
Request dispacther interface pptRequest dispacther interface ppt
Request dispacther interface ppt
 
Jsp advance part i
Jsp advance part iJsp advance part i
Jsp advance part i
 
Implicit Objects &Handling.pptx
Implicit Objects &Handling.pptxImplicit Objects &Handling.pptx
Implicit Objects &Handling.pptx
 
Jsp session 3
Jsp   session 3Jsp   session 3
Jsp session 3
 
JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)
 
JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGES
 
Introduction to JSP
Introduction to JSPIntroduction to JSP
Introduction to JSP
 
JSP - Java Server Page
JSP - Java Server PageJSP - Java Server Page
JSP - Java Server Page
 
Web&java. jsp
Web&java. jspWeb&java. jsp
Web&java. jsp
 
Web&java. jsp
Web&java. jspWeb&java. jsp
Web&java. jsp
 
3.jsp tutorial
3.jsp tutorial3.jsp tutorial
3.jsp tutorial
 
Jsp session implicit object
Jsp session implicit objectJsp session implicit object
Jsp session implicit object
 
Atul & shubha goswami jsp
Atul & shubha goswami jspAtul & shubha goswami jsp
Atul & shubha goswami jsp
 
JSP Components and Directives.pdf
JSP Components and Directives.pdfJSP Components and Directives.pdf
JSP Components and Directives.pdf
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
Lecture5
Lecture5Lecture5
Lecture5
 
Session 31 - Session Management, Best Practices, Design Patterns in Web Apps
Session 31 - Session Management, Best Practices, Design Patterns in Web AppsSession 31 - Session Management, Best Practices, Design Patterns in Web Apps
Session 31 - Session Management, Best Practices, Design Patterns in Web Apps
 

J2EE jsp_03

  • 1. Let’s Move on: JSP Objects An overview Biswabrata Banerjee
  • 2. JSP Objects Built-in JSP Objects and Their Implementation Classes: JSP Object Implementation Class Request HttpServletRequest response HttpServletResponse out JspWriter session HttpSession application ServletContext pageContext PageContext config ServletConfig page Object exception Throwable Biswabrata Banerjee
  • 3. Cont ‘d … JSP Objects These objects are implicitly created at the beginning of a page when your JSP is invoked, and they directly reference objects in the underlying servlet. They are always available to scriptlets and expressions. Biswabrata Banerjee
  • 4. a brief description The request Object The request object represents the current request from the browser and is a subclass of the ServletRequest class. For most current implementations of JSP, the request object is an instance of HttpServletRequest. The response Object Like the request object, the response object is usually a subclass of the HTTP-specific version of ServletResponse. In other words, it is usually an instance of HttpServletResponse. The out Object The out object is responsible for writing responses back to the browser and is an instance of the JspWriter class. The session Object The session object is an instance of HttpSession. Because there is an obvious dependence on HTTP, this object is available only if your JSPs use HTTP. The application Object The application object is an instance of the ServletContext object. The names "application" and "ServletContext" don't seem very similar, but if you recall what the ServletContext class does, you'll see that it manages data at the application level. Biswabrata Banerjee
  • 5. Cont ‘d… a brief description The pageContext Object The pageContext object is an instance of the PageContext class. Many of the items available through built-in variables are also available through the pageContext object. The config Object The config object gives you access to configuration information for your JSP and is an instance of the ServletConfig class. The page Object The page object is rather peculiar because it is a reference to the current JSP. In other words, it's like an alias for the this keyword in Java. The exception Object When you create an error page to deal with exceptions that occur during normal JSP processing, you might need access to the exception that caused the error page to be invoked. You can access that exception through the exception object. Biswabrata Banerjee
  • 6. Request Object JSP Request Object Request Object in JSP is used to get the values that the client passes to the web server during an HTTP request. The request object is used to take the value from the client’s web browser and pass it to the server. This is performed using an HTTP request such as: headers, cookies or arguments. The class or the interface name of the object request is http.httpservletrequest. The object request is written: Javax.servlet.http.httpservletrequest.
  • 7. Request Object Methods of request Object: There are numerous methods available for request Object. Some of them are: getCookies() getHeader(String name) getHeaderNames() getAttribute(String name) getAttributeNames() getMethod() getParameter(String name) getParameterNames() getParameterValues(String name) getQueryString() getRequestURI() getServletPath() setAttribute(String,Object) removeAttribute(String)
  • 8. Response Object JSP Response Object The response object denotes the HTTP Response data. The result or the information of a request is denoted with this object. The response object handles the output of the client. This contrasts with the request object. The class or the interface name of the response object is http.HttpServletResponse. The response object is written as : Javax.servlet.http.httpservletresponse. The response object is generally used by cookies. The response object is also used with HTTP Headers.
  • 9. Response Object Methods of response Object: There are numerous methods available for response object. Some of them are: setContentType() addCookie(Cookie cookie) addHeader(String name, String value) containsHeader(String name) setHeader(String name, String value) sendRedirect(String) sendError(int status_code)
  • 10. Session Object JSP Session Object Session Object denotes the data associated with a specific session of user. The class or the interface name of the object session is http.HttpSession. The object session is written as: Javax.servlet.http.httpsession. The previous two objects, request and response, are used to pass information from web browser to server and from server to web browser respectively.The Session object provides the connection or association between the client and the server. The main use of Session Objects is to maintain states when there are multiple page requests. The main feature of session object is to navigate between multiple pages in a application where variables are stored for the entire user session. The session objects do not lose the variables and the value remains for the user’ session. The concept of maintenance of sessions can be performed by cookies or URL rewriting. A detailed approach of session handling will be discusses in coming sections.
  • 11. Session Object Methods of session Object: There are numerous methods available for session object. Some of them are: getAttribute(String name) getAttributeNames isNew() getCreationTime getId invalidate() getLastAccessedTime getMaxInactiveInterval removeAttribute(String name) setAttribute(String, object)
  • 12. Out Object JSP out object JSP out object denotes the Output stream in the context of page. The class or the interface name of the object out is jsp.JspWriter. The out object is written as: Javax.servlet.jsp.JspWriter The object that write to the JSP's output stream is defined by the out object. Methods of out Object: There are numerous methods available for out Object,some of them are : clear clearBuffer flush isAutoFlush getBufferSize getRemaining newLine print println