CS4025/6095 Final Exam

 

9:00am – 12:00pm, April 23, 2007

 

Please write your answers in booklet(s).

 

1.     (10%) Give short answers to the following questions.

a)     What is the difference between client-side redirect and server-side redirect?

b)     Describe a simple Web application that can use either client-side redirect or server-side redirect in terms of functionality.

c)     Describe a simple Web application that can only use client-side redirect but not server-side redirect in terms of functionality.

d)     Describe a simple Web application that can only use server-side redirect but not client-side redirect in terms of functionality.

 

2.     (20%) The following is a database table with sample data for student course information.

 

    Student Course

SN

Last Name

First Name

Course ID

Year

Term

Grade

123

Gates

Bill

CS1234

2003

F

C+

456

Jobs

Steve

CS5678

2002

W

B-

 

a)     Define an XML schema to represent the information contained in the Student Course table in XML format.

 

b)     Write an XML data file according to the XML schema defined in (a) with the given sample data.

 

c)     Define an XSLT style sheet based on the XML schema defined in (a) to display XML data files that are instances of the XML schema.

 

3.     (20%) You are asked to write a simple Java Servlet to show the number of requests to this servlet, that is, how many times this servlet has been accessed by clients, for EACH of the following cases. Note that you can write a single servlet for all the cases, or for each case you write a separate servlet.

 

a)     The count of accesses to the servlet by all clients from any machines since the servlet started running.

 

b)     The count of accesses to the servlet by client(s) on a particular machine for a week (7 days or 7 * 24 hours).

 

c)     The count of accesses to the servlet by the current client within the same session.

 

d)     The count of accesses to the servlet by the submissions from the HTML/Form generated by this servlet.

 

The following is a sample template of the servlet. You can add and/or modify this code for your servlet(s). You do not need to copy the sample code to your booklet. You just need to indicate where to add your code or modify the sample code.

 

public class AccessCount extends HttpServlet {

  HttpServletRequest request;

  HttpServletResponse response;

  public void doPost(HttpServletRequest request,

     HttpServletResponse response) throws ServletException, IOException {

    this.request = request; this.response = response;

    controller();

  }

  public void doGet(HttpServletRequest request,

     HttpServletResponse response)throws ServletException, IOException {

     this.request = request; this.response = response;

     controller();

  }

  private void controller(){

    //add your code here

    generateCountPage(count, case);

  }

  private void generateCountPage(int count, String case) {       

    response.setContentType("text/html");

    try {

      writer = response.getWriter();

    } catch (Exception ex) {}  

    writer.println("<html><head>");

    writer.println("<title>Access Count</title></head> \n");

    writer.println("<body>");

    writer.println("This page has been accessed" + count + " times ");

    writer.println("in case: " + case + " <br />");

    writer.println("<form><input type=submit value=’Submit Again’>");

    writer.println("</form></body></html>");

  }

} 

 

4.     (20%) The following is a simple HTML/FORM file.

<html>

<head>

<title> Simple Form </title>

</head>

<body>

<form action="formcheck" method="POST">

Please select one of the following provinces: <br />

<input type="radio" name="province" value="NB"> New Brunswick <br />

<input type="radio" name="province" value="NS"> Nova Scotia <br />

Please enter your phone number with format ddd-ddd-ddd without white space.<br />

Telephone#: <input type="text" name=”phone> <br />

<input type="submit"> <input type="reset">

</form>

</body>

</html>

a)     Assume that New Brunswick is selected and the entered telephone number is (506)453-4666, when the form is submitted, what is the content of the HTTP request that the browser sends to the Web server?

 

b)     Write JavaScript code into the above HTML file to check the following two things:

§       The user-entered telephone number must follow the required syntax and all ‘d’s in the phone number must be a digit.

§       The area-code in the user-entered telephone number must be consistent with the selected provinces:

New Brunswick:         506

Nova Scotia:               902

            If the checking is successful, the form will be submitted to the server side. Otherwise an

error message will be displayed and the form will not be submitted.

 

c)     Write a server-side Perl/CGI, PHP, Servlet, JSP, or ASP.NET program to process a submission from the above HTML/FORM with JavaScript. The generated HTML file will display the submitted province and phone number along with the message “Your submission is confirmed”.

 

5.     (20%) You are asked to design a 2-tier web application for drivers to pay parking fine tickets online, according to the following user-case model and analysis model.

 

a)     For the view-parking-ticket-status use case, draw a UML class diagram to show MVC/Layered implementation of the use case using Servlet/JSP.

 

b)     For the pay-parking-ticket use case, without using AJAX, is it possible to check if the parking ticket exists in the server side immediately after the user entered a parking ticket number? If yes, how to do it? If not, why not? How to do it using AJAX?

Use case descriptions:

§       Pay Parking Ticket

The user enters a parking ticket number and her/his credit card information. The system validates and keeps the entered information and change the ticket status to payment being processed.

§       View Parking Ticket Status

The user enters a parking ticket number. The system shows the status of the ticket: unpaid, payment being processed, paid, or cancelled.

§       Create Parking Ticket

The user enters the relevant information for create a parking ticket for the system. The system validates the information and creates a ticket to be paid by the driver online.

§       Change Parking Ticket Status

The user enters a parking ticket number. The system shows the ticket. The user modifies the status of the ticket and/or other information.

§       Login

The user enters her/his login id and password. The system validates the entered user information against her/his account information in the system.

 

6.      (10%) You are asked to develop a web service to provide functions to sum and subtract two numbers. Write the WSDL specification and C# implementation of this web service. The following is a sample WSDL file and its C# implementation code. To answer this question, you can modify the sample WSDL file.

 

·        Service.cs

using System;

using System.Web;

using System.Web.Services;

using System.Web.Services.Protocols;

 

[WebService(Namespace = "http://isew.cs.unb.ca/numberService")]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

public class Service : System.Web.Services.WebService

{

    public Service () {

    }

 

    [WebMethod]

    public int inc(int n) {

        return n+1;

    }

 

    [WebMethod]

    public int dec(int n)

    {

        return n - 1;

    }

}

 

 

 

 

 

·        WSDL

<?xml version="1.0" encoding="utf-8" ?>

 <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://isew.cs.unb.ca/numberService" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://isew.cs.unb.ca/numberService" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">

<wsdl:types>

<s:schema elementFormDefault="qualified" targetNamespace="http://isew.cs.unb.ca/numberService">

<s:element name="inc">

<s:complexType>

<s:sequence>

        <s:element minOccurs="1" maxOccurs="1" name="n" type="s:int" />

  </s:sequence>

  </s:complexType>

  </s:element>

<s:element name="incResponse">

<s:complexType>

<s:sequence>

        <s:element minOccurs="1" maxOccurs="1" name="incResult" type="s:int" />

  </s:sequence>

  </s:complexType>

  </s:element>

<s:element name="dec">

 <s:complexType>

<s:sequence>

  <s:element minOccurs="1" maxOccurs="1" name="n" type="s:int" />

  </s:sequence>

  </s:complexType>

  </s:element>

<s:element name="decResponse">

<s:complexType>

<s:sequence>

        <s:element minOccurs="1" maxOccurs="1" name="decResult" type="s:int" />

  </s:sequence>

  </s:complexType>

  </s:element>

  </s:schema>

  </wsdl:types>

<wsdl:message name="incSoapIn">

  <wsdl:part name="parameters" element="tns:inc" />

  </wsdl:message>

<wsdl:message name="incSoapOut">

  <wsdl:part name="parameters" element="tns:incResponse" />

  </wsdl:message>

<wsdl:message name="decSoapIn">

  <wsdl:part name="parameters" element="tns:dec" />

  </wsdl:message>

<wsdl:message name="decSoapOut">

  <wsdl:part name="parameters" element="tns:decResponse" />

  </wsdl:message>

<wsdl:portType name="ServiceSoap">

<wsdl:operation name="inc">

  <wsdl:input message="tns:incSoapIn" />

  <wsdl:output message="tns:incSoapOut" />

  </wsdl:operation>

<wsdl:operation name="dec">

  <wsdl:input message="tns:decSoapIn" />

  <wsdl:output message="tns:decSoapOut" />

  </wsdl:operation>

  </wsdl:portType>

<wsdl:binding name="ServiceSoap" type="tns:ServiceSoap">

  <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />

<wsdl:operation name="inc">

  <soap:operation soapAction="http://isew.cs.unb.ca/numberService/inc" style="document" />

<wsdl:input>

  <soap:body use="literal" />

  </wsdl:input>

<wsdl:output>

  <soap:body use="literal" />

  </wsdl:output>

  </wsdl:operation>

<wsdl:operation name="dec">

  <soap:operation soapAction="http://isew.cs.unb.ca/numberService/dec" style="document" />

<wsdl:input>

  <soap:body use="literal" />

  </wsdl:input>

<wsdl:output>

  <soap:body use="literal" />

  </wsdl:output>

  </wsdl:operation>

  </wsdl:binding>

<wsdl:binding name="ServiceSoap12" type="tns:ServiceSoap">

  <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />

<wsdl:operation name="inc">

  <soap12:operation soapAction="http://isew.cs.unb.ca/numberService/inc" style="document" />

<wsdl:input>

  <soap12:body use="literal" />

  </wsdl:input>

<wsdl:output>

  <soap12:body use="literal" />

  </wsdl:output>

  </wsdl:operation>

<wsdl:operation name="dec">

  <soap12:operation soapAction="http://isew.cs.unb.ca/numberService/dec" style="document" />

<wsdl:input>

  <soap12:body use="literal" />

  </wsdl:input>

<wsdl:output>

  <soap12:body use="literal" />

  </wsdl:output>

  </wsdl:operation>

  </wsdl:binding>

<wsdl:service name="Service">

<wsdl:port name="ServiceSoap" binding="tns:ServiceSoap">

  <soap:address location="http://isew.cs.unb.ca/Service.asmx" />

  </wsdl:port>

<wsdl:port name="ServiceSoap12" binding="tns:ServiceSoap12">

  <soap12:address location="http://isew.cs.unb.ca/Service.asmx" />

  </wsdl:port>

  </wsdl:service>