meljun_cortes_jedi slides-web programming-chapter01-introduction to the course

Upload: meljun-cortes-mbampa

Post on 06-Apr-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 MELJUN_CORTES_JEDI Slides-Web Programming-Chapter01-Introduction to the Course

    1/32

    Introduction to WebProgramming

    Web Programming

  • 8/3/2019 MELJUN_CORTES_JEDI Slides-Web Programming-Chapter01-Introduction to the Course

    2/32

    Why the Web?

    2Web Programming

    Technology-Neutral Environment

    Communication is done through popular protocols (HTML/HTTP)

    Users only need a web browser

  • 8/3/2019 MELJUN_CORTES_JEDI Slides-Web Programming-Chapter01-Introduction to the Course

    3/32

    Why the Web?

    3Web Programming

    Ease of Distribution/Updates

    Distribution

    No need to give away programs through CDs.

    No need to go through a possibly lengthy installation sequence.

    The users only need the location of the application in the Internet.

    Updates

    No need to periodically check for newer versions of the program.

    Problem of how to actually get the program updates is eliminated.

    Users need not even be informed of an update; The codebase in the web serveronly needs to be updated and all users automatically will enjoy the benefits of theupdates.

  • 8/3/2019 MELJUN_CORTES_JEDI Slides-Web Programming-Chapter01-Introduction to the Course

    4/32

    Client-Server Architecture

    4Web Programming

    Client-server architecture

    Used by web applications.

    A client program connects to a server for information that it needs tocomplete the tasks that the user has set it to do.

    Thick and Thin clients

    Thin clients

    Contain only a minimum of what is required for the user experience, mostly onlyan interface.

    Thick clients Aside from an interface, also contain some, if not many, of the processing logic

    required for user-specified tasks.

  • 8/3/2019 MELJUN_CORTES_JEDI Slides-Web Programming-Chapter01-Introduction to the Course

    5/32

    Client-Server Architecture

    5Web Programming

    Client-server architecture from a web perspective

    Web applications use thin clients.

    The client program, a browser in this case, is only an interface thatthe user makes use of to perform tasks.

    Everything else resides on the server.

  • 8/3/2019 MELJUN_CORTES_JEDI Slides-Web Programming-Chapter01-Introduction to the Course

    6/32

    Client-Server Architecture

    6Web Programming

    Client-server architecture from a web perspective

    Web server

    The server takes in requests from web browser clients and returns a response

    Server response (containsthe document requested bythe user or an error code ifthe item does not exist)

    Client request (containsthe name and addressof the item the client islooking for)

    Machine running aWeb Server

    Machine runninga Web Browser

    Serverprocessesclient requestby looking forthe resourcerequested bythe client

  • 8/3/2019 MELJUN_CORTES_JEDI Slides-Web Programming-Chapter01-Introduction to the Course

    7/32

    Client-Server Architecture

    7Web Programming

    Client-server architecture from a web perspective

    Web client

    The browser provides the user with an interface that helps the user to issuerequests to the server and to view the server's response.

  • 8/3/2019 MELJUN_CORTES_JEDI Slides-Web Programming-Chapter01-Introduction to the Course

    8/32

    HTML

    8Web Programming

    Hypertext Markup Language

    A set of instructions for the web browser on how to presentcontent to the user.

    An open standard updated by the World Wide WebConsortium (W3C).

    All browsers know what to do when it encounters HTML,although some older browsers might have problems inrendering some pages that were written using newer

    versions of HTML that were updated after theirdevelopment.

  • 8/3/2019 MELJUN_CORTES_JEDI Slides-Web Programming-Chapter01-Introduction to the Course

    9/32

    HTTP

    9Web Programming

    Hypertext TransferProtocol

    A network protocol with Web-specific features that runs ontop of two other protocol layers, TCP and IP, to make surethat requests and responses are delivered completelybetween each end of the communication.

    TCP makes sure that a file sent from one end of a network isdelivered completely and successfully at its destination.

    IP routes file pieces from one host to another on their way to itsdestination. HTTP uses these two protocols.

  • 8/3/2019 MELJUN_CORTES_JEDI Slides-Web Programming-Chapter01-Introduction to the Course

    10/32

    HTTP

    10Web Programming

    Uses a Request/Response sequence

    HTTP client opens a connection and sends a request message to anHTTP server.

    Server returns a response message and closes the connection.

    Request and response messages

    Similar and English-oriented

    Consist of:

    an initial line

    zero or more header lines

    a blank line and an optional message body

  • 8/3/2019 MELJUN_CORTES_JEDI Slides-Web Programming-Chapter01-Introduction to the Course

    11/32

    HTTP Requests

    11Web Programming

    Requests from the client to the server contain:

    The information about the kind of data the user is requesting

    A method name, which tells the server the kind of request beingmade, as well as how the rest of the message from the client isformatted

    GET

    POST

  • 8/3/2019 MELJUN_CORTES_JEDI Slides-Web Programming-Chapter01-Introduction to the Course

    12/32

    HTTP Requests: GET

    12Web Programming

    Simplest HTTP method

    Used mainly to request a particular resource from theserver, whether it be a web page, a graphic image file, adocument, etc.

    Can also be used to send data over to the server

    Limitations

    Total amount of characters that can be encapsulated is limited.

    Data sent is simply appended to the URL sent to the server.

    Advantage URL requesting can be bookmarked by the browser.

  • 8/3/2019 MELJUN_CORTES_JEDI Slides-Web Programming-Chapter01-Introduction to the Course

    13/32

    GET: Sample URL

    13Web Programming

    http://jedi-master.dev.java.net/servlets/NewsItemView?newsItemID=2359&filter=true

    All of the items before the question mark (?) is the originalURL of the request.

    http://jedi-master.dev.java.net/servlets/NewsItemView

    Everything after that are the parameters or data that yousend along to the server.

    Parameters are encoded as name and value pairs.

    Format: name=value

    If there are more than one set of parameters, they are separatedusing the ampersand symbol (&).

    newsItemID=2359&filter=true

  • 8/3/2019 MELJUN_CORTES_JEDI Slides-Web Programming-Chapter01-Introduction to the Course

    14/32

    HTTP Requests: POST

    14Web Programming

    Designed such that the browser can make:

    Complex requests to the server

    Simple requests that require uploading of files to the server

    Encapsulates or hides the data inside of the message bodyit sends to the server.

  • 8/3/2019 MELJUN_CORTES_JEDI Slides-Web Programming-Chapter01-Introduction to the Course

    15/32

    HTTP Response

    15Web Programming

    Also contains both headers and a message body

    Headers

    Different from that of HTTP requests

    Contain: Information about the version of the HTTP protocol that the server is using

    Content type that is encapsulated within the message body

    MIME-type

    Value for the content type

    Tells the browser if the message contains HTML, a picture, or someother type of content

  • 8/3/2019 MELJUN_CORTES_JEDI Slides-Web Programming-Chapter01-Introduction to the Course

    16/32

    Dynamic over Static Pages

    16Web Programming

    Content

    Static content does not change

    e.g. archived newspaper articles, family pictures from an online photo gallery

    Dynamic content changes according to user input

    Dynamic pages have a lot more flexibility and have moreutility than static pages.

  • 8/3/2019 MELJUN_CORTES_JEDI Slides-Web Programming-Chapter01-Introduction to the Course

    17/32

    Dynamic over Static Pages

    17Web Programming

    Some scenarios where dynamic content is the only thingthat will fit the bill:

    The Web page is based on data submitted by the user.

    e.g. results pages from search engines, orders for e-commerce sites

    The data changes frequently.

    e.g. weather report or news headlines page built dunamically

    The Web page uses information from corporate databases or othersuch sources.

  • 8/3/2019 MELJUN_CORTES_JEDI Slides-Web Programming-Chapter01-Introduction to the Course

    18/32

    Java 2 Enterprise Edition

    (J2EE)

    18Web Programming

    A platform introduced for the development of enterpriseapplications in a component-based manner

    Uses a distributed multi-tier application model Distributed: most applications designed and developed with this

    platform can have their different components installed in differentmachines

    Multi-tier: applications are designed with multiple degrees of

    separation with regards to the various major components of theapplication

  • 8/3/2019 MELJUN_CORTES_JEDI Slides-Web Programming-Chapter01-Introduction to the Course

    19/32

    J2EE: Multi-Tiered

    Application Example

    19Web Programming

    A web application has:

    The presentation layer (the client browser)

    The business logic layer (the program that resides on the web server) The storage layer (the database which will handle the application data)

    The layers of a web application are distinctly separated, butare all needed to create one application for the user

  • 8/3/2019 MELJUN_CORTES_JEDI Slides-Web Programming-Chapter01-Introduction to the Course

    20/32

    J2EE Web Tier Overview

    20Web Programming

    Web Tier

    One of the tiers in the J2EE platform

    The layer which interacts with browsers in order to create dynamiccontent

    Two technologies within this layer:

    Servlets

    JavaServerPages (JSP)

  • 8/3/2019 MELJUN_CORTES_JEDI Slides-Web Programming-Chapter01-Introduction to the Course

    21/32

    J2EE Web Tier Overview

    21Web Programming

  • 8/3/2019 MELJUN_CORTES_JEDI Slides-Web Programming-Chapter01-Introduction to the Course

    22/32

    Web Tier: Servlets

    22Web Programming

    Java's primary answer for adding additional functionality toservers that use a request-response model

    Have the ability to read data contained in the requestspassed to the server and generate a dynamic responsebased on that data

    Not necessarily limited to HTTP-based situations, but arecurrently their primary use, so Java has provided an HTTP-specific version that implements HTTP-specific features

  • 8/3/2019 MELJUN_CORTES_JEDI Slides-Web Programming-Chapter01-Introduction to the Course

    23/32

    Servlets Disadvantage

    23Web Programming

    Servlets

    Since servlets are simply Java language classes, they produceoutput the way other Java programs would: through printingcharacters as Strings into the output stream, in this case the HTTP-

    response. Problems:

    HTML can be quite complex and could be very hard to encode through the use ofString literals.

    Engaging the services of a dedicated graphics and web page designer to help inthe static parts of the pages is hard if not impossible.

  • 8/3/2019 MELJUN_CORTES_JEDI Slides-Web Programming-Chapter01-Introduction to the Course

    24/32

    Web Tier: JavaServerPages

    24Web Programming

    Looks just like HTML, only it has access to all the dynamiccapabilities of servlets through the use of scripts andexpression languages

    Designers can concentrate on simple HTML design andsimply leave placeholders for developers to fill with dynamiccontent

  • 8/3/2019 MELJUN_CORTES_JEDI Slides-Web Programming-Chapter01-Introduction to the Course

    25/32

    Containers

    25Web Programming

    All J2EE components rely on the existence of a container;without the appropriate container, they would not run.

  • 8/3/2019 MELJUN_CORTES_JEDI Slides-Web Programming-Chapter01-Introduction to the Course

    26/32

    Containers

    26Web Programming

    Features

    Communications support

    Lifecycle management

    Multi-threading support Declarative security

    JSP Support

  • 8/3/2019 MELJUN_CORTES_JEDI Slides-Web Programming-Chapter01-Introduction to the Course

    27/32

    Basic Structure of a Java

    Web Application

    27Web Programming

    For a container to recognize your application as a valid web application,it must conform to a specific directory structure:

    Contains HTML, images, other static content, plus JSPs

    Contains meta-information about your application (optional)

    All contents of this folder cannot be seen from the web browser

    Contains class files of Java classes created for this application (optional)

    Contains JAR files of any third-party libraries used by your app (optional)

    XML file storing the configuration entries for your application

  • 8/3/2019 MELJUN_CORTES_JEDI Slides-Web Programming-Chapter01-Introduction to the Course

    28/32

    Basic Structure of a Java

    Web Application

    28Web Programming

    There are some points regarding this structure:

    One: The top-level folder (the one containing your application) doesNOT need to be named Document Root. It can be, in fact, named

    any way that you like, though it is highly recommended that the top-level folder name be the same name as your application. It is onlynamed Document Root in the figure to indicate that it serves as theroot folder of the files or documents in your application.

  • 8/3/2019 MELJUN_CORTES_JEDI Slides-Web Programming-Chapter01-Introduction to the Course

    29/32

    Basic Structure of a Java

    Web Application

    29Web Programming

    There are some points regarding this structure:

    Two: Any other folder can be created within this directory structure.For example, for developers wishing to organize their content, they

    can create an images folder from within the document root to hold alltheir graphics files, or maybe a configdirectory inside the WEB-INFfolder to hold additional configuration information. As long as theprescribed structure as shown above is followed, the container willallow additions.

  • 8/3/2019 MELJUN_CORTES_JEDI Slides-Web Programming-Chapter01-Introduction to the Course

    30/32

    Basic Structure of a Java

    Web Application

    30Web Programming

    There are some points regarding this structure:

    Three: The capitalization on the WEB-INF folder is intentional. Thelowercaps on classes and lib are intentional as well. Not following

    the capitalization on any of these folders will result in yourapplication not being able to see the contents of these folders.

  • 8/3/2019 MELJUN_CORTES_JEDI Slides-Web Programming-Chapter01-Introduction to the Course

    31/32

    Basic Structure of a Java

    Web Application

    31Web Programming

    There are some points regarding this structure:

    Four: All contents of the WEB-INF folder cannot be seen from thebrowser. The container automatically manages things such that, for

    the browser, this folder does not exist. This mechanism protectsyour sensitive resources such as Java class files, applicationconfiguration, etc. The contents of this folder can only be accessedby your application.

  • 8/3/2019 MELJUN_CORTES_JEDI Slides-Web Programming-Chapter01-Introduction to the Course

    32/32

    Basic Structure of a Java

    Web Application

    32Web Programming

    There are some points regarding this structure:

    Five: There MUST be a file named web.xml inside the WEB-INFfolder. Even if, for example, your web application contains only static

    content and does not make use of Java classes or library files, thecontainer will still require your application to have these two items.