Presentation is loading. Please wait.

Presentation is loading. Please wait.

Servlets 4 Lec 30 Web Design and Development. Looking Back… Response Redirection  Sending a standard redirect  Sending a redirect to an error page Request.

Similar presentations


Presentation on theme: "Servlets 4 Lec 30 Web Design and Development. Looking Back… Response Redirection  Sending a standard redirect  Sending a redirect to an error page Request."— Presentation transcript:

1 Servlets 4 Lec 30 Web Design and Development

2 Looking Back… Response Redirection  Sending a standard redirect  Sending a redirect to an error page Request Dispatching  Forward  Include

3 Include Diagram

4 Example Code Request Dispatching: include

5 Forward Diagram

6 Example Code Request Dispatching: forward

7 HTTPServletRequest methods

8 More HttpServletRequest methods setAttribute (String, Object) / getAttribute(String)  Stores an attribute in this request as key-value pair form  Attributes are set/reset between requests  Often used in conjunction with RequestDispatcher

9 More HttpServletRequest methods cont. getMethod()  Returns the name of HTTP method (get & post etc) getRequestURL()  Returns the part of this request’s URL  Query string is not included getProtocol()  Returns the name & version of the protocol used

10 More HttpServletRequest methods cont. getHeaderNames()  Returns an enumeration of all the header names this request contains getHeader(String headername)  Returns the value of the specified request header as String  Returns null, if no header with the specified name

11 HTTPServletResponse methods

12 More HttpServletResponse methods setContentType(String)  Servlets almost always use this header  MIME types setContentLength(int)  Sets the Content-Length header. addCookie(Cookie)  Adds a value to the Set-Cookie header. sendRedirect (String)  Redirect client to the specified URL  Can accept relatives URL

13 Session Tracking

14 HTTP is a stateless protocol  Every request is considered independent of every other request Many web applications need to maintain a conversational state with the client  A shopping cart is a classic example

15 Continuity Problem (User’s Point of View) Page 1 Page 2 Page 3 Page 4 Server State Added book to cart CC# = XXX Billing address Order submitted & logged Credit: Stanford’s java course

16 The illusion of Continuity User thinks that choices made on page 1 are remembered on page 3 However  HTTP is Stateless  Requests from same user do not necessarily come in adjacent requests

17 Continuity Problem (Server’s Point of View) Request 1 Request 2 Credit: Stanford’s java course


Download ppt "Servlets 4 Lec 30 Web Design and Development. Looking Back… Response Redirection  Sending a standard redirect  Sending a redirect to an error page Request."

Similar presentations


Ads by Google