Practical 3

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Computer Science 2B

Practical Assignment 3 16 August 2011 Time: Deadline 2011-08-16 16h30 Marks: 30

Practical assignments must be uploaded to eve.uj.ac.za before the end of your session on 2011-08-16 (please check EVE for your respective session). Remember to SUBMIT your work during your session otherwise you will get 0. In this practical, you will create custom web server (that can also be accessed by your browser of choice) and a very basic custom web browser (that has basic Navigation capabilities).

Web Server

Your web server should therefore be able to understand the commands sent by a typical web browser and it needs to return the requested document or display an error message correctly. Vendors use the RFC 2616 document on the HTTP protocol to develop web browsers that are compatible with HTTP/1.1 (but you can Google it to get the full specication). Your Web Server must be able to serve any web page that is stored in the directory where the server runs from. You can use your own html pages to demonstrate that it works correctly. If you type http://127.0.0.1/MyPage.html in your respective browser, it should display the MyPage.html document. The web server should wait on port 80 and like many other web servers it should be able to do the following: If a loop back is entered (http://127.0.0.1 or localhost) the default document is served (index.html). If the specied document exists, it should be served to the browser. If the web server cannot nd the document, it should serve an error page which informs the user that the page does not exist. The web server should be able to serve more than one request (use a endless loop that checks for incoming requests).

Page 1 of 2

Computer Science 2B

Practical Assignment 3

16 August 2011

Please remember to send the correct headers to the browser, so that it knows what type of information will be expected. For HTML the header should look like: "HTTP/1.0 200 OK\r\n Content-Type: text/html\rn\n\r\n"

Web Browser

Your web browser should then be able to issue requests and render the respective pages returned from the web server. From your rst practical, you learnt how to retrieve HTML pages from a web server and save it locally. A browser performs a similar task, but instead of saving it to le, it renders the HTML retrieved from the web server. In our case we simply render the HTML using the JEditorPane in Java. In order to achieve this, we perform the following: Create a JFrame that contains a JTexteld for URL input, a JButton to conrm input (GO button) and a JEditorPane to display the retrieved HTML. When a user enters the URL in the texteld and clicks the GO button, the URL from the texteld is used to set the JEditorPane page and renders the HTML document retrieved from the URL. Please note. You do not have to implement additional link navigation within the page itself! If the JEditorPane throws an Exception, a message dialog should be shown to the user to indicate that the page could not be found.

Marksheet
1. (a) Default HTML document served to the browser (with http://127.0.0.1) (b) Serves any other HTML document that exists that is local to the server. (c) Serves a Page not found if the document specied does not exist. (d) HTML documents are not hard-coded in the source code but are retrieved from real HTML les. 2. (a) Web Browser has a JTextField for the URL, JButton for the GO Button and a JEditorPane for rendering the HTML. (b) JEditorPane navigates to the URL specied and renders the retrieved HTML. (c) Displays an error if page could not be found. [5] [5] [5] [5] [3] [4] [3]

Page 2 of 2

You might also like