CP311 - Internet Programming and Applications II

Examination Answers


QUESTION THREE

a. HTTP is a stateless protocol. Explain. (1 Mark)

b. Explain the two ways to make HTTP a stateful protocol. (1 Mark)

c. Explain the differences between Simple Object Access Protocol (SOAP) and Representational State Transfer (REST) web services. (2 Marks)

d. PHP is “a weakly typed language”. Explain what this statement means as regards to php variables. (1 Mark)


QUESTION FOUR

You have been hired as a front end developer at one of the E-Commerce company. The first day of your work at the company you realize that company’s website is not okay. You decided to use bootstrap framework to revamp the website to make it more attractive and user friendly. Among the features of the bootstrap you have decided to use are carousel and pagination. You have decided to divide the contents of the website into five pages ie. page1.html, page2.html, page3.html, page4.html and page5.html. Among the images that describe the company are image1.jpg, image2.jpg, image3.jpg, image4.jpg and image5.jpg. You thought it will be better if the images will be in a slide show. In your design show how you will use bootstrap carousel and pagination to create a slide show of the mentioned images and pagination of the mentioned pages respectively. Hint: use carousel-indicator class to show the captions of each slide, carousel-inner class to add slides to the carousel, carousel-control-prev and carousel-control-next class to allow the user to go back and forward between the slides. (15 Marks)


QUESTION FIVE

a. Create an Ajax-based product catalog that obtains its data from JSON files located on the server. The data should be separated into four JSON files. The first file should be a summary file, containing a list of products. Each product should have a title, an image filename for a thumbnail image and a price. The second file should contain a list of descriptions for each product. The third file should contain a list of filenames for the full-size product images. The last file should contain a list of the thumbnail image file names. Each item in a catalogue should have a unique ID that should be included with the entries for that product in every file. Next, create an Ajax-enabled web page that displays the product information in a table. The catalog should initially display a list of product names with their associated thumbnail images and prices. When the mouse hovers over a thumbnail image, the larger product image should be displayed. When the user moves the mouse away from that image, the original thumbnail should be redisplayed. You should provide a button that the user can click to display the product description. (7 Marks)

b. Write a PHP script that obtains a URL and its description from a user through html form and stores the information into a database using MySQL. Use URL and URLtable as the name of the database and table respectively. The first field of the table should contain an actual URL, and the second, which is named Description, should contain a description of the URL. Use www.udom.ac.tz as the first URL, and input UDOM as its description. The second URL should be www.ratiba.udom.ac.tz, and the description should be UDOM Time Table System. The third URL should be www.civeclassroom.udom.ac.tz, and its description should be CIVE digital classroom. The fourth URL should be www.civeipt.udom.ac.tz, and its description should be CIVE Industrial Practical Training. After each new URL is submitted, print the contents of the database in a table format. Use server side validation to make sure that the fields for URL and Description should accept empty values and should not contain spaces before and at the end. (8 Marks)


QUESTION SIX

a. XML plays an important role in the current world of web development. It is completely beneficial for those who want to use web technology to distribute information across the web.

i. Create a web service in xml format which contain information of the students such as: Students first name, last name, RegNo, Age, Gender, Courses, and Program. (3 Marks)

ii. Using PHP write a script that will read the XML web service in part (i) and display the results in a web browser in JSON format. (3 Marks)

b. Suppose that there is a web service named adventure.php, located on your web server in the same directory as your code. This service outputs XML data describing a situation and options a player can pick (you can choose your own adventure style game). In this problem you will use Ajax to contact the web service (using a GET request), examine its XML data, and display the questions and options in the game. The XML data returned by the web service consists of an overall document element called adventure that contains a situation tag, an answers tag and an end tag. The answers tag contains a series of one or more answer elements inside it. The format of the XML matches the following.

 <adventure>
     <situation>The dragon is looking at you</situation>
     <answers>
         <answer>run screaming</answer>
         <answer>draw your sword</answer>
        <answer>be very polite</answer>
        <answer>sneeze</answer>
     </answers>
     <end reason="ooh! The dragon accidentally stepped on you" />
 </adventure>

Assume the code you are writing will go into adventure.js, linked from the following script.

 <body>
    <h1>Choose your own adventure</h1>
    <div id="container">
        <fieldset id="situation">
            <p id="situationparagraph"></p>
        </fieldset>
       <fieldset id="answer"></fieldset>
    </div>
</body>
 

When the page loads send an AJAX request to the adventure.php service and pass it a parameter named situation with the value begin. Insert the questions you get back into the situationparagraph. Add a button to the answer fieldset for each answer tag you receive. Set these buttons so that if they are clicked your page will send an Ajax request to adventure.php with the situation parameter set to the text on the button. This request will return the same sort of data which should be dealt with in the same way. The buttons displayed should only ever be the current options, no old options should show. If instead of receiving XML back that contains a question tag you receive XML with an end tag, place the text of the reason attribute of the end tag in the situationparagraph and make sure no buttons are showing. (9 Marks)


QUESTION SEVEN

The University of Dodoma through its College of Informatics and Virtual Education (CIVE) has decided to create a web system to manage the whole process of Industrial Practical Training (IPT). The system was developed using PHP and MySQL database. The system has two parts, which are source codes and database. The database part is hosted at the server with IP Address 192.168.10.10 and the source code is hosted at the server with IP Address 192.168.10.20.

After the system has been deployed it was observed that the performance was poor as the system loads very slowly especially when the information are retrieved from the server. It was observed that the problem was due to huge amount of data that are loaded from the server. As an expert in web development, you have been consulted to give your advice. In your advice you suggested AJAX technology to be used to load data from the server to the client side so as to improve performance. Assume you want to load the following information from the table student (FName, SName, Program, Gender and RegNo). Write a script hosted at the source code server to show how you connect to the database, load data from the server using AJAX and display to the client in a table format. Use JQuery methods to send the AJAX requests. Use the following credentials to access the database server: Udom_IPT as a database name, Password: 123_abc, username: udom_cive. (15 Marks)


End of Examination Answers