1 / 44

Web Applications and Java EE5

Web Applications and Java EE5. Dr. N. A. Joshi. Agenda. Exploring the HTTP Protocol Introducing Web Applications Describing Web Containers Building Web Applications. Exploring the HTTP Protocol. HTTP is a communication model Used to transfer information on the internet Stateless protocol

zona
Download Presentation

Web Applications and Java EE5

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. Web ApplicationsandJava EE5 Dr. N. A. Joshi

  2. Agenda • Exploring the HTTP Protocol • Introducing Web Applications • Describing Web Containers • Building Web Applications

  3. Exploring the HTTP Protocol • HTTP is a communication model • Used to transfer information on the internet • Stateless protocol • Application-level protocol • HTTP facilitates • types of requests that client can send to servers, and • types of responses that server can send to clients

  4. The Hyper Text Transfer Protocol (HTTP) • HTTP is a connection-oriented, stateless, request-response protocol. • An HTTP server, or web server, runs on TCP port 80 by default. • HTTP clients, colloquially called web browsers, are processes which implements HTTP to interacts with a web server to retrieve documents phrased in HTML, whose contents are displayed according to the documents’ markups.

  5. The Hyper Text Transfer Protocol (HTTP) • In HTTP/1.0, each connection allows only one round of request-response. • A client obtains a connection, issues a request • The server processes the request, issues a response, and closes the connection thereafter.

  6. The HyperText Transfer Protocol (HTTP) • HTTP is text-based: the request and responses are character strings. • Each request and response is composed of these parts, in order: • The request/response line • A header section • A blank line • The body

  7. A sample HTTP session

  8. The HTTP request • A client request is sent to the server after the client has established a connection to the server. • A request line is of the following form: <HTTP method><space><Request-URI><space><protocol specification>\r\n where • <HTTP method> is the name of a method defined for the protocol, • <Request-URI> is the URI of a web document, or, more generally, a web object, • <protocol specification> is a specification of the protocol observed by the client, and • <space> is a space character. • An example client request is as follows: GET /index.html HTTP/1.0

  9. HTTP Methods in a client request • The HTTP method in a client request is a reserved word (in uppercase) which specifies an operation of the server that the client desires. • Some of the key client request methods are listed below: ~ GET: for retrieving the contents of web object referenced by the specified URL ~ HEAD: for retrieving a header from the server only, not the object itself. ~ POST: used to send data to a process on the server host. ~ PUT: used to request the server to store the contents enclosed with the request to the server machine in the file location specified by the URL. ~ DELETE: removes the resource identified by the request URL, from the server. ~ OPTIONS: returns the HTTP methods that the server supports. ~ TRACE: invokes a remote application layer associated with a request message.

  10. The GET Request method • Simplest and the most frequently used request method • Used to access the static resources, such as HTML documents and images • It can be used retrieve dynamic information by including query parameters in the request URL • E.g. http://abc.com?name-Joshi • Here ‘name’ is a parameter having value ‘Joshi’ • GET method contains a request Uniform Resource Identifier (URI), • which is used to retrieve information form the request. • It is (URI) is generally in the form of an entity.

  11. The GET Request method • If the request-URI refers to the data-producing process, • the produced data, not the source-code of the process is returned as the entity in the response; unless the text happens to be the output of the process. • What is ‘Conditional GET method’? (pg. 39) • What is ‘Partial GET method’? (pg. 39)

  12. The HEAD Request method • Sometimes, a client might only need to view the header of a response (Content-type or Content-Length). • Then, client can use the HEAD request method to retrieve the header • Similar to GET method, except that • the server does return a message body in the response of the HEAD method • It can be used to retrieve the meta information of the entity requested by the user. • Response of HEAD method is cacheable (pg. 39)

  13. The POST Request method • Commonly used for accessing dynamic resources, or • when a large amount of complex information is to be sent to the server • The web server accepts the entity enclosed in the request as a new subordinate of the resource identified by the request-URI. • Its sub-functionalities: • Providing annotations of existing resources • Posting a message to a bulletin board, newsgroup, mailing list, or a similar group of articles • Providing a block of data (such as result of submitting a form, to a data-handling process) • Extending database through an append operation

  14. The POST Request method • Sometimes, an action performed by the POST method does not result in the retrieval of a resource that can be identified by a URI. • In such a case, either 200 (OK) or 204(No Content) response status is generated, depending on whether or not the response includes an entity that describes the result. • The response is 201 (created) when the requested resource has been created on the origin server. • A POST request allows the encapsulation of multi-part messages into the request body. • E.g. we can use POST requests to upload text or binary files from the server. • lly, we can use POST requests in applets to send serializable java objects, or even raw bytes to the web server. • POST requests offer a wider choice than GET requests in terms of the contents of a request

  15. Difference: GET & POST

  16. The PUT Request method • The PUT request method stores an entity in the specified Request-URI • The entity is a resource residing on the web server under the specified Request-URI.

  17. The DELETE Request method • It requests the web server to delete the resource identified by URI. • 200 (OK) response code specifies that the resource has been deleted successfully. • 202 (Accepted) response code specifies that the resource has not yet been deleted. • 204 (No Content) response code specifies that the resource has been deleted but the response does not include an entity. • This method is not cacheable; this method permanently deletes the files from the cache as well.

  18. The OPTIONS Request method

  19. The TRACE Request method

  20. The Request Header • “The request header fields allow the client to pass additional information about the request, and about the client itself, to the server. These fields act as request modifiers, with semantics equivalent to the parameters on a programming language method (procedure) invocation.” • A header is composed of one or more lines, each line in the form of <keyword>: <value>\r\n

  21. The Request Header Some of the keywords and values that may appear in a request header are: • Accept: content types acceptable by the client • User-Agent: specifies the type of browser • Connection: “Keep-Alive” can be specified so that the server does not immediately close a connection after sending a response. • Host: host name of the server An example request header is as follows: Accept: */* Connection: Keep-Alive Host: www.someU.edu User-Agent: Generic

  22. Request Body • A request optionally ends with a request body, which contains data that needs to be transferred to the server in association with the request. • For example, if the POST method is specified in the request line, then the body contains data to be passed to the target process. (This is an important feature and will become clearer when we discuss CGI, servlet, and SOAP.)

  23. Examples of a complete client request Example1: GET / HTTP/1.1 <blank line> Example2: HEAD / HTTP/1.1 Accept: */* Connection: Keep-Alive Host: somehost.com User-Agent: Generic <blank line>

  24. Examples of a complete client request Example3: POST /servlet/myServer.servlet HTTP/1.0 Accept: */* Connection: Keep-Alive Host: somehost.com User-Agent: Generic <blank line> Name=donald&email=donald@someU.edu

  25. The HTTP Server Response • In response to a request received from a client, the HTTP server sends to it a response. • Like the request, an HTTP response is composed of these parts, in order: 1. The response or status line 2.   A header section 3.   A blank line 4.   The body

  26. The response status line The status line is in the form of: <protocol><sp><status-code><sp><description>\r\n The status code designations are as follows: 100-199 Informational 200-299 Client request successful 300-399 Client request redirected 400-499 Client request incomplete 500-599 Server errors Example 1: HTTP/1.0 200 OK Example 2: HTTP/1.1 404 NOT FOUND

  27. HTTP Response Header • The status line is followed by a response header. A response header is composed of one or more lines, each line in the form of <keyword>: <value>\r\n • There are two types of response header lines: • Response header lines • Entity headerlines

  28. HTTP Response Header Response header lines – these header lines return information about the response, the server, and further access to the resource requested, as follows: Age: seconds Location: URI Retry-After: date|seconds Server: string WWW-Authenticate: scheme realm

  29. HTTP Response Header Entity headerlines – these header lines contain information about the contents of the object requested by the client, as follows: Content-Encoding Content-Length Content-Type: type/subtype (see MIME) Expires: date Last-Modified: date

  30. HTTP Response Header An Example response header is as follows: Date: Mon, 30 Oct 2000 18:52:08 GMT Server: Apache/1.3.9 (Unix) ApacheJServ/1.0 Last-modified: Mon, 17 June 2001 16:45:13 GMT Content-Length: 1255 Connection: close Content-Type: text/html • The Content-Type specifies the type of the data, using the contents type designation of the MIME protocol. • The Content-Encoding specifies the encoding scheme (such as uuencode or base64) of the data, usually for the purpose of data compression. • The expiration date gives the date/time (specified in a format defined with HTTP)after which the web object should be considered stale • The Last-Modifed date specifies the date that the object was last modified.

  31. HTTP Response Body The body of the response follows the header and a blank line, and contains the contents of the web object requested. HTTP/1.1 200 OK Date: Sat, 15 Sep 2001 06:55:30 GMT Server: Apache/1.3.9 (Unix) ApacheJServ/1.0 Last-Modified: Mon, 30 Apr 2001 23:02:36 GMT ETag: "5b381-ec-3aedef0c" Accept-Ranges: bytes Content-Length: 236 Connection: close Content-Type: text/html <html> <head> <title>My web page </title> </head> <body> Hello world! </BODY></HTML>

  32. Introducing Web Applications • A web-application • is a server-side application, • that contains • Web Components (Servlets, JSP pages), • HTML/XML documents, and other resources • in a directory structure or archived format, • known as a Web Archive (WAR) file. • It is generally located at a central-server, which provides services to various clients • In a web server, the web components can be conveniently distributed as Java Archive (JAR) files with the .war extenstion

  33. Introducing Web Applications • Web-application are of two types: • Presentation-oriented: • Generates dynamic content and interactive web pages containing various types of markup language (HTML, XML) in response to requests. • Presentation-oriented applications are often clients of Service-oriented web applications. • Service-oriented: • Implements the web service, and • is invoked by presentation-oriented web applications.

  34. Introducing Web Applications

  35. Introducing Web Applications • Server-side application development requires the following: • A programming model & API: • Specify how to develop applications • Server-side runtime support: • Includes support for applicable network services, and • a runtime for executing the applications • Deployment support • Includes support for installing the application on the server. • It also deploys configuring the application components such as • Specifying initialization parameters, and specifying any database.

  36. Components of a Web Application • A web application consists of web components (Servlets, JSPs) • Earlier, web-applications used to face maintenance problems, • which were solved by using the Model/View/Controller (MVC) paradigm for building user interfaces. • Generally, • JSPs are used for creating a dynamic response or view. • Servlets, containing the logic for managing requests, act as the controller. • Existing business rules are the model.

  37. Components of a Web Application

  38. Servlet vs. CGI • Servlets perform better than CGI; e.g.- • Once a servlet is loaded into memory, it can run on a single lightweight thread; while CGI scripts must be loaded in a different process for every request • Servlet can maintain a pool of database connections which save time in processing the requests • Servlets eliminate much of the complexity of retrieving parameters from an HTTP request. • Servlets provide uniform APIs to maintain the session data throughout web application and interact with user requests.

  39. Java Server Pages • JSP pages are text based documents that are executed as Servlets, • but allow a more natural approach to creating static content. • they are also designed to provide dynamic content. • How it was introduced: • Servlet technology was developed as a mechanism • to accept the requests from browsers, • retrieve the enterprise data from application tier or databases, • perform application logic on the data, and • format that data for presentation in the browser (HTML). • A servlet makes use of print statements to post the HTML data, both hard-coded tags and dynamic content based on the enterprise data retrieved from the back-end tiers, back to the user’s browser.

  40. Java Server Pages • How it was introduced: • … • Web designers faced few difficulties using HTML in print statements. • difficulty in previewing • difficulty in locating the appropriate section of code in a servlet when data or display format changes (when presentation logic and content are intermixed) • Moreover, change in the servlet would require recompilation and reloading into the web server • A mechanism to specify the mapping from a JavaBeans component to the HTML (or XML) presentation format is provided by JSP pages. • It clearly defines the application logic, helping content developers and web application developers work efficiently. • Content developers need not be java experts • Web application developers need not be expert web designers

  41. JSTL & JSF • JSP Tag Library • is a set or library used by JSP for implementing JSTL tags • Java Server Faces • It is a framework to build user interfaces for web applications

  42. Types of web components • Web components are of two types: Presentation & front components • Presentation component: • They generate HTML/XML responses, which determine the user interface when rendered • When a JSP page acts as a presentation component, it may contain reusable custom tags or presentation logic. • Front component:

  43. Types of web components

  44. References • Java Server Programming – Java EE 5 Black Book • http://www.oracle.com/technetwork/java/index.html

More Related