Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 61 Processing the Client Request JavaServer Pages By Xue Bai.

Similar presentations


Presentation on theme: "Chapter 61 Processing the Client Request JavaServer Pages By Xue Bai."— Presentation transcript:

1 Chapter 61 Processing the Client Request JavaServer Pages By Xue Bai

2 Chapter 62 Objectives In this chapter, you will: Obtain header information using the request object Get client and server information using the request object Process form input fields Get and use array containing all values of a single input field Control output stream

3 Chapter 63 The Implicit Objects There are a number of objects made available by the JSP container These objects are called implicit objects, because you can use them without explicitly declaring them in your page These objects are instances of classes defined by the servlet and JSP specifications Request, response, out, session, application, and exception

4 Chapter 64 Request object Each time you request a JSPpage, the JSP container creates a new instance of the request object The object contains information about the request and the invoked page, including headers, client and server information, request URL, cookies, session, and input data

5 Chapter 65 Header Information HTTP requests can have a number of associated HTTP headers These headers provide some extra information about the request You can use the header information to customize the content you send to client

6 Chapter 66 Header Name Description AcceptSpecify the media type, Multipurpose Internet Multimedia Extensions (MIME), the client prefers to accept. All media types are separated by commas. For example, the image format a browser prefers. User-AgentGives information about the client software, including the browser name and version as well as information about the client computer. For example, Mozilla/4.0 (compatible; MSIE 6.0b; Windows NT 5.1) indicates it is Microsoft Internet Explorer running on Windows XP. ReferrerGives the URL of the document that refers to the requested URL (that is, the document that contains the link the client followed to access this document). Accept- Language The default language setting on the client machine

7 Chapter 67 Get Header Information –It returns a string containing information about the header passed as a parameter request.getHeader(“header name”); Example: –The string returned by request.getHeader(“accept- language”) indicates the default language setting on the client machine The method request.getHeaderNames() returns an enumeration of all header names on the current request

8 Chapter 68 Header Information

9 Chapter 69 Determine Browser Type You are using Internet Explorer You are using Netscape Navigator You are using a browser other than Netscape Navigator or Internet Explorer

10 Chapter 610 Example2.jsp Displayed in Internet Explorer

11 Chapter 611 Example2.jsp Displayed in Netscape Navigator

12 Chapter 612 Get Client and Server Information The request object provides various methods to get client computer name and IP, Web server name, and Web server port Client computer name: Client computer IP address: The Web server name: The running port number of Web server:

13 Chapter 613 Form Collection Use input elements to collect data: –These input elements include text, password, text area, hidden, select, checkbox, and radio inputs

14 Chapter 614 Text Field Accept single-line information –maxlength—Sets the maximum allowable length of the field, in characters –size—Sets the width, in characters, of the input box that appears on the page –value—Sets initial value for the text field

15 Chapter 615 Password Field Characters are converted to asterisk or bullet symbols for privacy

16 Chapter 616 Hidden Field Another type of txt field, but they are not displayed Used to send data to the Web server that cannot be changed by users Often used to pass data from one page to another

17 Chapter 617 TextArea Accept multiple lines