Pace CS 396S - Web Programming Using a Simple Server

Unformatted text preview:

Web Programming Using a Simple ServerHypertext Markup Language (HTML) was developed by Tim Berners-Lee in 1992 along with his invention of Hypertext Transfer Protocol (HTTP). Together HTML and HTTP created the World Wide Web. Berners-Lee adapted Standard Generalized Markup Language (SGML) tags for HTML, carrying over some basic ones. HTML is used by browsers such as Internet Explorer and Firefox to format web pages.Many web sites are only used to convey information, however, some also request information from the user and process that information. The most familiar example is that of e-commerce. Stores provide forms that users fill out with their buying choices and credit card data. Forms are used in many other contexts as well including logins and registrations.The computer on the web site is called a server and the user’s computer is referred to as the client. There are a number of commercial and open-source servers available including ones from Microsoft, SUN, and the Apache Jakarta Project. They all use basic networking protocols. A very simple version of a server will be described below. It is helpful to students who wish to learn something about web programming without having to get into the complications involved with a full server.Network Programming using the Java Programming LanguageHypertext Transfer ProtocolA Java Program with a Client SocketA Simple Web ServerThe Client’s Web PageThe Server ClassThe Email Example ProgramThe Request ClassThe Response ClassUsing the Web ServerReferencesWeb Programming Using a Simple ServerHypertext Markup Language (HTML) was developed by Tim Berners-Lee in 19921 along with his invention of Hypertext Transfer Protocol (HTTP). Together HTML and HTTP created the World Wide Web. Berners-Lee adapted Standard Generalized Markup Language2 (SGML) tags for HTML, carrying over some basic ones. HTML is used by browsers such as Internet Explorer and Firefox to format web pages.Many web sites are only used to convey information, however, some also request information from the user and process that information. The most familiar example is that of e-commerce. Stores provide forms that users fill out with their buying choices and credit card data. Forms are used in many other contexts as well including logins and registrations.The computer on the web site is called a server and the user’s computer is referred to as the client. There are a number of commercial and open-source servers available including ones from Microsoft, SUN, and the Apache Jakarta Project.3 They all use basic networking protocols. A very simple version of a server will be described below. It is helpful to students who wish to learn something about web programming without having to get into the complications involved with a full server.Network Programming using the Java Programming LanguageThe Java language has several classes that are used for network programming. They are in the java.net package and are adaptations of the corresponding structures in C. The C structures were introduced in theearly 1980s by researchers in Berkeley while working with the UNIX operating system. The Socket classis used for connecting client computers to a network, and the ServerSocket class is used by servers to wait for incoming requests from clients. The SocketImpl class is an abstract class that is the super class of all classes that implement sockets. SocketImpl has four fields, the address of the host computer, the file descriptor, the localport on the clientcomputer, and the port on the host computer to which the client is connected. The host address may be something like www.cnn.com, the Internet address of the Cable News Network. The port (an integer) could be 80, the standard port for accessing web pages on web servers.The Socket class is a subclass of SocketImpl and is used to create a client connection. The name comes from a wall socket that is used to connect an electrical device, such as a lamp, to a source of electrical power. The connection can be over a local area network (LAN), the Internet, or even using the local loop within the computer itself. The local loop has the network address 127.0.0.1. It is often given the name, localhost.41 Dave Raggett , A History of HTML, Chapter 2, Addison Wesley Longman, 1998, http://www.w3.org/People/Raggett/book4/ch02.html.2 SGML was developed in the 1960s and 1970s. It was standardized by the ISL (International Standards Organization) in 1986.3 The Apache Project is located at http://jakarta.apache.org/.4 In Windows 2000 or XP, you can set localhost as an Environment Variable. Go into Settings/Control Panel/System/Advanced/System Variables. Choose New and then enter localhost as the Variable name and 127.0.0.1 as the Variable value. In Windows 98, use Windows Explorer to find Autoexec.bat. It is in the C:\System folder. Edit it and add the line SET localhost=127.0.0.1. When you next boot up your computer, this file will be executed and will set the environment variable.1When a socket is created and opened by a Java program, it uses the Transmission Control Protocol (TCP) /Internet Protocol (IP) or the User Datagram Protocol (UDP). TCP/IP is the principal network protocol architecture used on the Internet. UDP is simpler and used when network reliability is not a problem. TCP is a stream oriented protocol. That means that applications see input and output as streamsof data rather than discrete packets or frames. Therefore programmers can treat network input and output in the same way as they do keyboard, screen and file I/O.Hypertext Transfer ProtocolThe World Wide Web primarily uses the Hypertext Transfer Protocol (HTTP). HTTP sits on top of TCP/IP and adds functionality needed for web actions such as sending requests, receiving responses and following hyperlinks from one web address to another. It is designed for rapid hops across the Internet and so keeps a connection open for just one transaction. HTTP is said to be stateless. That means that a web server has no memory of its clients. Internet companies manage this either by depositing a cookie on the client’s computer or by issuing a session identification number included in the URL string. For example, the following URL string was generated by the barnesandnoble.com server:http://www.barnesandnoble.com/bookstore.asp?userid=0FJHK58GK6The userid for this specific session is 0FJHK58GK6. It follows the user as he or she moves around the web site.


View Full Document
Download Web Programming Using a Simple Server
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Web Programming Using a Simple Server and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Web Programming Using a Simple Server 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?