1 / 19

JAVA SERVER PAGES

JAVA SERVER PAGES. ASHIMA KALRA. INDEX……. INTRODUCTION TO JSP IMPLICIT OBJECTS COOKIES. Introduction to JSP.

kerri
Download Presentation

JAVA SERVER PAGES

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JAVA SERVER PAGES ASHIMA KALRA

  2. INDEX……. • INTRODUCTION TO JSP • IMPLICIT OBJECTS • COOKIES

  3. Introduction to JSP JSP stands for JavaServer Pages. JSP is one of the most powerful, easy-to-use and fundamental technology for Java web developers. JSP combines HTML, XML, Java Servlet and JavaBeans technologies into one highly productive technology to allow web developers to develop reliable, high performance and platform independent web applications and dynamic websites BACK

  4. Introduction to JSP JSP Implicit Objects JSP container provides a list of instantiated objects for you to access different kind of data in a web application. Those objects are called implicit object because it is automatically available to access. These are some main implicit objects in JSP which you use most: BACK

  5. Introduction to JSP • request object • response object • session object • out object • pageContext object • application object • config object • page object • exception object

  6. Introduction to JSP The request object Each time a client requests a JSP page, the JSP engine creates a new object to represents that request called request object.  The request object is an instance of class javax.servlet.http.HttpServletRequest. The request object contains all information about the current HTTP request and the clients.  Be noted that request object only available in a scope of the current request. It is re-created each time new request is made. By using methods of the request object you can access almost information such as HTTP header, query string, cookies...

  7. Introduction to JSP The response object JSP also creates the response object which is an instance of class javax.servlet.http.HttpServletResponse. The response object represents the response to the client. By using this object you can add new cookies, change MIME content type of the page. make the page redirect to the other page.

  8. Introduction to JSP The session object The session object is used to track information of a particular client between multiple requests. the session object is avaible in the server so it can helps you to overcome the stateless of HTTP protocol. You can use session object to store a arbitrary information between client requests. The session object is an instance of class javax.servlet.http.HttpSession.

  9. Introduction to JSP The out object The output stream is exposed to the JSP through the out object. the out object is an instance of class javax.servlet.jsp.JspWriter.

  10. Introduction to JSP The pageContext object The pageContext object represent the entire JSP page. You can use the pageContext object to get page attributes of a page. the pageContext object is an instance of class javax.servlet.jsp.pagecontext.

  11. Introduction to JSP The application object The application object is a representation of JSP page through its life cycle.  The application object is created when a JSP page is initialized and removed when the JSP page is removed by jspDestroy() method or JSP page is recompiled. As its name imply, the information of the application object is accessible to any object used within the JSP page.

  12. Introduction to JSP The config object The config object allows you to access the initialization parameters for the Servlet and JSP engine. The config object is an instance of the class javax.servlet.ServletConfig. The page object The page object is an instance of a JSP page. By using the page object, you can call any method of the page's servlet. The exception object The exception object contains the exception which is thrown from the previous JSP page. You can use the exception object to generate friendly error message based on erorr condition to the end-user. BACK

  13. Introduction to JSPCookies Cookies are short pieces of data sent by web servers to the client browser. The cookies are saved to clients hard disk in the form of small text file. Cookies helps the web servers to identify web users, by this way server tracks the user. Cookies pay very important role in the session tracking. Cookie Class In JSP cookie are the object of the class javax.servlet.http.Cookie. This class is used to creates a cookie, a small amount of information sent by a servlet. BACK

  14. Introduction to JSP Web browser, saved by the browser, and later sent back to the server. A cookie's value can uniquely identify a client, so cookies are commonly used for session management. A cookie has a name, a single value, and optional attributes such as a comment, path and domain qualifiers, a maximum age, and a version number. The getCookies() method of the request object returns an array of Cookie objects. Cookies can be constructed using the following code: Cookie(java.lang.String name, java.lang.String value)

  15. Introduction to JSP <%@ page language="java" %><html><head><title>Cookie Input Form</title></head><body><form method="post" action="setcookie.jsp"><p><b>Enter Your Name: </b><input type="text" name="username"><br><input type="submit" value="Submit"></form></body>

  16. Introduction to JSP Above form prompts the user to enter the user name. User input are posted to the setcookie.jsp file, which sets the cookie. Here is the code of setcookie.jsp file: <%@ page language="java" import="java.util.*"%> <%String username=request.getParameter("username");if(username==null) username="“;Date now = new Date();String timestamp = now.toString();Cookie cookie = new Cookie ("username",username);cookie.setMaxAge(365 * 24 * 60 * 60); BACK

  17. Introduction to JSP response.addCookie(cookie);%> Above Code Set a Cookie . ------------Now Code to access the stored cookies------------- <%@ page language="java" %><%String cookieName = "username";Cookie cookies [] = request.getCookies ();Cookie myCookie = null;

  18. Introduction to JSP if (cookies != null){for (int i = 0; i < cookies.length; i++) { if (cookies [i].getName().equals (cookieName)) { <p>Welcome: <%=myCookie.getValue()%>. } }}%> BACK

  19. THANKYOU

More Related