Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
FACULTY OF ENGINEERING
MAY 2015
INSTRUCTIONS TO CANDIDATES
CarZone Company Ltd is a car dealer who sells used Japanese cars. The company
would like to setup a web site to advertise its vehicles in stock. One of the main features
will include test drive feedback from potential buyers. The following web page
review.html will allow buyers to send their reviews online after the test drive. The
review form can be accessed from the local server using the url:
http://localhost/webcentric/testdrive/review.html. Note that fields having an asterix(*) next
to their label are required.
Figure 1: review.html
1
WEB-CENTRIC COMPUTING – CSE 1023Y(1)
Additional information:
QUESTION 1
a) When a request is made for review.html, the html code is transported in the body of
the response constructed by the local server.
i) Write the Request-Line of the request sent to the server given that http 1.1 was
used.
(2 Marks)
ii) Write the Status-Line and Content-Type of the response received given that http
1.1 was used and the request was successfully processed. Assume that the
browser history was cleared before the request was sent.
(2+1 Marks)
iii) Implement review.html in HTML5 using the screenshot (Figure 1) in the case
study and the additional information provided. Note: information from all
elements is to be submitted to the page review_process.php using the POST
method.
(10 Marks)
b) Once the review page has been successfully implemented, the web developer
decides to upload the review page on the following domain: www.car.com. The
review page can then be accessed using the new url: http://www.car.com/review.html.
With the help of a diagram, explain how the www.car.com domain is resolved.
Assume that the web server is assigned IP address 100.21.14.92.
(5+5 Marks)
QUESTION 2
a) The web developer decides to add some formatting to the review page (Figure 1).
An external CSS style myStyle.css has been defined to format the HTML page.
The css file is located in a subfolder called style.
Style Information
body
{
background-color: Beige;
color: black;
font: 12pt Arial;
}
Code Listing 1: myStyle.css
Using CSS 3.0 selectors, write down the style information that should be added
to mystyle.css (Code Listing 1).
(3+3 Marks)
function validatePhone( ){
var value = document.getElementById(txtPhone).value;
if(!regExp.test(“value”)){
alert(“You have not provided a valid phone number!”);
return false;
}
return true;
}
Code Listing 2: Function validatePhone( )
(Continue next page)
3
WEB-CENTRIC COMPUTING – CSE 1023Y(1)
QUESTION 2 (Continued)
You are required to identify the errors in Code Listing 2 and re-write the correct
JavaScript function codes.
(5 Marks)
Figure 2: review_process.php
i) Write the codes for review_process.php which retrieves and displays the input
values as shown in Figure 2. State any assumptions made.
(8 Marks)
ii) The Http protocol is stateless; each request is processed without any
knowledge of any prior or future requests. Sessions can be used to store user-
specific preferences.
Explain how you would use sessions in review_process.php to allow only one
review per person. Support your answer using sample codes.
4
WEB-CENTRIC COMPUTING – CSE 1023Y(1)
QUESTION 2 (Continued)
If the person tries to submit the review form (Figure 1) twice, the following
message is displayed.
Figure 3: session
(2+4 Marks)
5
WEB-CENTRIC COMPUTING – CSE 1023Y(1)
QUESTION 3
The form also provides a textbox (txtCode) where a discount code can be entered and
the value of the discount (divDiscount) will be deducted from the order value and
shown in the order total (divOrderTotal) as shown below.
For example, in Figure 4 above, the code “600D-LUCK-M8” was entered and the
‘Apply’ button was clicked. The code was sent to the server through AJAX. The server
sent back a discount amount of 25 (percent) in XML format.
The HTML codes for the ‘Apply’ button in the order details form is given in Code Listing
3 below.
6
WEB-CENTRIC COMPUTING – CSE 1023Y(1)
QUESTION 3 (Continued)
When the button is clicked, the ajax function sendAjaxRequest from file Ajax.js is called
with the relevant parameters.
You are required to complete the AJAX functionality according to the requirements
below:
i. Required data shall be sent to the checkDiscount.php for processing via POST
method.
ii. XML data processed by the server shall be returned to an anonymous callback
function pointed by the processAjaxResponse variable.
iii. The returned XML shall be checked and discount applied accordingly or
message stating why discount cannot be applied shall be displayed.
Possibility 1
<?xml version='1.0' encoding='UTF-8'>
<discount>25</discount>
OR
Possibility 2
<?xml version='1.0' encoding='UTF-8'>
<discount>Invalid or Expired code!</discount>
OR
Possibility 3
<?xml version='1.0' encoding='UTF-8'>
<discount>No code provided!</discount>
Note:
The discount amount is retrieved from the database and it can be any other value
between 10 to 90. In case the value is a number, then the discount is displayed in
divDiscount and divOrderTotal is updated by substracting that amount to it.
QUESTION 3 (Continued)
In case a string is obtained as discount (possibilities 2 & 3) then only the divMessage is
updated with the text string.
function createAjaxRequest(){
// The new XMLHttpRequest codes should work on all modern browsers.
try { return new XMLHttpRequest(); } catch(e) {}
// ActiveXObjects used by older IE browser - Not Shown.
alert("XMLHttpRequest not supported");
return null;
}
/*************************************************
8
(Continue next page)
WEB-CENTRIC COMPUTING – CSE 1023Y(1)
divOrderTotal.innerHTML = divOrderValue.innerHTML;
if(divDiscount.hasChildNodes()){
divDiscount.removeChild(divDiscount.childNodes[0]);
}
if(divMessage.hasChildNodes()){
divMessage.removeChild(divMessage.childNodes[0]);
}
/************************************************
* Missing Code(s) – JS3 *
* ***********************************************
* Hint(s) *
* 1. Read XML *
* 2. Calculate discount and load values in divs, etc *
* 3. isNaN() js function can be used to check if *
data in the xml is number or string *
Usage: isNaN(‘Error’) evaluated to true *
* 4. Else load string message (possibilities 2 or 3) *
************************************************/
9
WEB-CENTRIC COMPUTING – CSE 1023Y(1)
}else{
divMessage.innerHTML = "An error has occured.";
}
}
}
Code Listing 5: Ajax.js
(a) You are required to complete all the missing code JS1 – JS3 sections based on the
requirements specified above and any other detail given in the Ajax.js file. Do
NOT use the jQuery or any other Javascript library for the code implementation.
(7+2+8 Marks)
The request from the Ajax function is sent to checkDiscount.php which connects to the
PL2015 database through the DBConnect.class.php file to generate the XML in Code
Listing 4.
The DBConnect.class.php initiates the connection to the database and is given in Code
Listing 6 below.
<?php
class DbConnect{
const DB_HOST = 'localhost'; const DB_USER = 'root'; const DB_PASSWORD = '';
const DB_DATABASE = 'PL2015';
public static $conn;
10
WEB-CENTRIC COMPUTING – CSE 1023Y(1)
The SQL statement in Code Lisitng 7 below shall help to retrieve the discount amount
given a valid code, provided that it has not expired.
$sql = "SELECT Amount FROM Discount WHERE Code = '" . $code . "' AND Expired =
0";
Code Listing 7: SQL Statement
Sample data retrieved by the SQL statement when value of variable $code is 600D-
LUCK-M8 is shown in Figure 6 below.
11
WEB-CENTRIC COMPUTING – CSE 1023Y(1)
<?php
error_reporting(E_ALL ^ (E_WARNING | E_DEPRECATED));
header("Cache-Control: no-cache");
header("Pragma: no-cache");
date_default_timezone_set("Indian/Mauritius");
require_once('DbConnect.class.php');
$strDiscount = "";
if (!empty($_POST['txtCode'])) {
$code = $_POST['txtCode'];
$sql = "SELECT Amount FROM Discount WHERE Code = '" . $code . "' AND Expired
= 0";
DbConnect::initialise();
$dbResult = mysql_query($sql, DBConnect::$conn) or die(mysql_error());
?>
Code Listing 8: checkDiscount.php
Note:
(b) You are required to complete all the missing code PHP1 – PHP2 sections based on
the requirements given above and any other detail given in the checkDiscount.php
file.
(1+7 Marks)
12
WEB-CENTRIC COMPUTING – CSE 1023Y(1)
QUESTION 4
A SOAP Web Service is being developed to allow the service consumers to view
Premier League football match results per week in a football season.
WSDL
The match results were compiled by the Football Association over the years and are
now being exposed as a Web Service. The corresponding WSDL, league.wsdl, is shown
in Code Listing 9 below.
13
WEB-CENTRIC COMPUTING – CSE 1023Y(1)
<types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.shehzad.edu/webservice"
elementFormDefault="qualified">
<xs:element name="Input">
<xs:complexType>
<xs:sequence>
<xs:element name="Season" type="xs:string"/>
<xs:element name="Week" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="LeagueType">
<xs:sequence>
<xs:element name="Season" type="xs:string"/>
<xs:element name="Week" type="xs:string"/>
<xs:element name="Match" type="xs:string"/>
<xs:element name="Score" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ArrayOfLeagueResults">
<xs:sequence>
<xs:element name="LeagueResults" minOccurs="0"
maxOccurs="unbounded" type="this:LeagueType"/>
</xs:sequence>
</xs:complexType>
<xs:element name="Result" type="this:ArrayOfLeagueResults"/>
</xs:schema>
</types>
14
WEB-CENTRIC COMPUTING – CSE 1023Y(1)
<portType name="LeagueServicePortType">
<operation name="viewLeagueResults">
<input message="this:getLeagueRequest"/>
<output message="this:getLeagueResponse"/>
</operation>
</portType>
<service name="LeagueService">
<port name="LeagueServicePort" binding="this:LeagueServiceBinding">
<soap:address
location="http://localhost/CSE1023YExamJune2015Q4/Server.php"/>
</port>
</service>
</definitions>
Code Listing 9: League.wsdl
15
WEB-CENTRIC COMPUTING – CSE 1023Y(1)
QUESTION 4 (Continued)
id & name =
‘sltSeason’
id & name =
‘txtWeek’
SOAP Request
<SOAP-ENV:Envelope xmlns:SOAP-
ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:we="http://www.shehzad.edu/webservice">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<!—Missing Code: SOAP Request -->
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Code Listing 10: Soap Request
Given that the 2014/2015 season was selected and week 26 was entered in the user
interface (Figure 7) and submitted to the server.
QUESTION 4 (Continued)
SOAP Server
The Server component of the web service (Server.php) exposes the Web Service and
handles requests from the web service client (Client.php).
<?php
error_reporting(E_ALL ^ (E_WARNING | E_DEPRECATED));
header("Cache-Control: no-cache");
header("Pragma: no-cache");
require_once('DBConnect.class.php');
require_once('PLHandler.class.php');
$server->handle();
?>
Code Listing 11: Server.php
The SQL statement below will retrieve the Season, Week, Match and Score details for
matches played in a certain week in a particular season.
QUESTION 4 (Continued)
Sample data retrieved by the SQL statement when value of variable $season is
2014/2015 and $week is 26 is shown in Figure 8 below.
(13 Marks)
18
WEB-CENTRIC COMPUTING – CSE 1023Y(1)
QUESTION 4 (Continued)
SOAP Client
When the Client.php receives the SOAP response sent by the server, it processes the
response and displays the data as shown in Figure 9 below.
QUESTION 4 (Continued)
<?php
if((isset($_POST['sltSeason'])) && (!empty($_POST['txtWeek']))){
try{
$season = $_POST['sltSeason'];
$week = $_POST['txtWeek'];
$wsdl = 'http://localhost/CSE1023YExamJune2015Q4/WS/League.wsdl';
$options = array('cache_wsdl'=>'WSDL_CACHE_NONE',
'features'=>'SOAP_SINGLE_ELEMENT_ARRAYS');
$HTMLDocument .= "</tbody>
</table>
<p><strong></strong>Premier League Service Application 2015.</p>
</body>
</html>";
echo $HTMLDocument;
}
20
WEB-CENTRIC COMPUTING – CSE 1023Y(1)
else{
echo "<h1>No League Result found in database!</h1>";
}
}
catch (Exception $e) {
echo 'Exception: '.$e->getMessage();
}
catch (SOAPFault $exception) {
echo 'SOAP Exception: '.$exception->getMessage();
}
}
else{
header("Location: http://localhost/CSE1023YExamJune2015Q4/index.html");
}
?>
Code Listing 13: Client.php
c) You are required to complete all the missing code WS1 – WS3 sections based on
the details specified above and any other information given in the Client.php file.
(3+1+4 Marks)
21