ITC357ITC557 Sample Exam-2 / Mock Exam

fortunabrontideInternet και Εφαρμογές Web

13 Νοε 2013 (πριν από 3 χρόνια και 7 μήνες)

83 εμφανίσεις

Page
1

of
10


ITC357ITC557


Sample Exam
-
2

/ Mock Exam

Question
-
1


30
MCQs

(Final Exam has 60 MCQs)



60 Marks


Q1. A Web
-
based Information System (WBIS) is…

a)

Same as a web publishing site

b)

Different to a web publishing site as a WBIS generates web pages by server
site s
oftware.

c)

Not tailed to each user

d)

Not capable of interfacing to data storages


Q2. The following is not a Web
-
based Information System (WBIS).

a)

A web site for a newspaper with only static web pages.

b)

A search engine

c)

On
-
line shopping site

d)

A travel booking sit
e


Q3. The following is a collection of server technologies.

a)

HTTP Server, Java Beans, SSL, Plug
-
ins

b)

HTTP Server, Java Beans, SSL, Zope

c)

HTTP Server, Java Beans, SSL, Active
-
X

d)

HTTP Server, Java Beans, SSL, Cookies


Q4. A thicker web client software may inclu
de the following e
mbedded
a
pplication
s:

a)

Java Applet, Flash Component,
Java Beans, Java Scripts

b)

Java Applet,
JSP code
, Active
-
X Compone
nt, Java Scripts

c)

Java
Servlets
, Flash Component, Active
-
X Compone
nt, Java Scripts

d)

Java Applet, Flash Component, Active
-
X C
omponent, Java Scripts


Q5. C
lient
-
side programming

has the advantage(s) of…

a)

Immediate response

b)

Reduced network traffic

c)

Reduced server load

d)

All of the above


Q6.
For a
HTTP
response
:

a)

the header includes the type of content being returned and the body is bl
ank

b)

the header includes the name of the page and the body is blank

c)

the header includes the name of the p
age

and the body can contain the form
data

d)

the header includes the type of content being returned and the body contains
the content, normally an HTML pa
ge or part of a page, such as an image


Q7.
The following is
not

a m
echanism for invoking a server
-
side program from the
web browser:

a)

Request a URL which refers to a remote program (eg. by following an HREF
link)

b)

Request a page containing an <id> attribute

with source that refers to a
variable in a remote program

c)

Submit a <FORM> whose action refers to a remote program

Page
2

of
10


d)

Request a page that refers to a remote program in a server
-
side include or
containing embedded scripts (eg. ASP, Cold Fusion, JSP, PHP, Zope)


Q8.
An e
xample(s) for
applying
server side includes:

a)

Displaying information, such as the system date, or the last modified date of
the file

b)

Including HTML from another file

c)

Invoking a program on the server or
e
xecuting a command on the server (eg. a
Unix

command)

d)

All of the above


Q9.
I
n the CGI process

t
he web server makes form data or URL parameters available
through


a)

environment variables

b)

standard inp
ut

c)

environment variables or standard input

d)

a session object


Q10.
In passing CGI form data…

a)

Data from

a form is sent to the server as a string of name
-
value pairs, such as
award=bit&age=34

b)

Data from a form is sent to the server as a
n array

of name
s followed by
value
s
,
such as

award
, age,
bit
,
34
’.

c)

The METHOD attribute of the FORM
does not
determines whet
her an HTTP
GET or POST request is used to send the data.

d)

The way that the data is sent and the way that the CGI program retrieves it
does not differ

depending on whether GET or POST is used.


Q11.
The following show some lines found in
Servlet
c
onfigurati
on in web.xml

file of
an Apache web server. The contents of which of the following tags will appear as a
part of the URL?

a)

<servlet
-
name>hello</servlet
-
name>

b)

<servlet
-
class>HelloServlet</servlet
-
class>

c)

<url
-
pattern>/helloworld</url
-
pattern>

d)

None of

the abov
e


Q12.

Why do we use session objects?

a)

To allow users to login and then view a number of pages and
t
o allow
users to
fill
multi
-
screen forms;

b)

To "carry around" data, such as a "shopping cart";

c)

To develop a profile of each user (what they have viewed before
, what they
are interested in etc
.
)

d)

To achieve all of the above


Q13.

The correct way(s) to set a Cookie named
nationality

with the value ‘Indian’ in a
Servlet is/are.

a)

Set
-
cookie: nationality=indian

b)

response.setHeader("Set
-
Cookie","nationality=Indian");

c)

Co
okie cook=new Cookie("nationality","Indian");

response.addCookie(cook);

Page
3

of
10


d)

Both b) and c)


Q14.

Which of the following code correctly reads the value of the Cookie nationality
from a session object?

a)

String nation=session.getAttribute("nationality");

b)

String na
tion=session.get
Parameter
("nationality");

c)

String nation=session.get
Value
("nationality");

d)

String nation=session.get
Field
("nationality");


Q15.

Which is not a
JSP Implicit Objects
?

a)

request

b)

cookie

c)

response

d)

session


Q16.

An example for an expression in JSP is.

a)

<%! static int hitcount = 1; %>

b)

<%= now.get(Calendar.YEAR) %>

c)

<%@ page import="java.sql.*" %>

d)

<% out.println("h1>Customer Details</h1>");%>


Q17.

Which is
incorrect

about
asymmetric
or

public key cryptography
?

a)

Uses one key for encrypting and another for d
ecrypting.

b)

One key is kept private and the other is made public.

c)

To send a message to you I encrypt using your public key.

d)

Requires much lower computation time.


Q18.

A ‘m
essage
d
igest
function’ …

a)

produces a numeric value from a message

that is sent with
the message for
message verification

b)

is a short message encrypted with my private key

c)

verif
ies

a

public key of a given person

d)

decrypt
s

the certificate and extract the person’s public key


Q19.

… is
not

an XML rule.

a)

XML d
ocuments
m
ust
h
ave a
r
oot
e
lement

b)

X
ML t
ags are
c
ase
s
ensitive

c)

XML
e
lements
m
ust be
p
roperly
n
ested

d)

XML elements must start with a capital letter


Q20.

The following is a simple XML file:


<?XML version = "1.0" standalone="no"?>

<!DOCTYPE curry SYSTEM="http://www.cookery.com/curry.dtd">

<cur
ry style="Vindaloo" origin="India">

<ingredient>cumin</ingredient>

<ingredient>cinnamon</ingredient>

</curry>



Page
4

of
10


In this file ‘style’ is

a)

The root element

b)

a child element

c)

an attribute

d)

a data type


Q
2
1. Which of the following JSP code makes the data
in Custo
mer
Bean

available to
the JSP script?

a)

<jsp:useBean id="customer" scope="session" class="CustomerBean"/>

b)

<jsp:useBean id="
customer
" scope="
page
" class="
Customer
Bean"/>

c)

<jsp:useBean id="
customer
" scope="session" class="
c
ustomer
Bean"/>

d)

<jsp:useBean id="
custome
r
" scope="
page
" class="
c
ustomer
Bean"/>


Q2
2
. Which is correct about the following JSP code?

<%

<table>

<c:forEach items="${timetableBean.flights}" var=“flight">

<tr>

<td><c:out value="${flight.date}"/></td>

<td><c:out value="${flight.flightNumber}"/></td>

<td><c:out value="${flight.departureTime}"/></td>

<!
--
similarly for other attributes
--
>

</tr>

</c:forEach>

</table>

%>

a)

It stores flight details of multiple flights into a Java Bean named
timetableBean

b)

It stores flight details of multiple flights into a se
ssion object named flight

c)

It displays flight details of multiple flights as a HTML table.

d)

It uses JSP tags to store flight details of multiple flights into a Java Bean
named timetableBean


Q
2
3.
The JSP Standard Tag Library (JSTL)


a)

Is a

standard tag librar
y developed as an extension to the JSP standard that is
implemented using Java code.

b)

Is the only Tag Library developed for JSP as
JSP standard is
not
extensible

c)

defines only c
ore (iteration, conditional logic, output, variable manipulation)

tags

d)

makes the
work of a web designer difficult


Q
2
4.
Using JSTL t
he code:

<jsp:useBean id="bookmark" scope="session" class="BookmarkBean"/>

<jsp:getProperty name="bookmark" property="title"/>

c
an be simplified to:

a)

${title}

b)

${bookmark.title}

c)

{bookmark.title}

d)

${title
.

boo
kmark
}



Page
5

of
10


Q
2
5.
JSTL uses …………… for selection.

a)

<c:if
> tag only

b)

<c:choose>

tag
only

c)

Non
e

of a) or b)

d)

Both a) and b)


Q
26
.
A Database is


a)

a structured col
lection of related items of information

b)

a structured collection of related items of data

c)

a structured col
lection of related items of fields

d)

a structured col
lection of related items of records


Q2
7
. A Servlet can access a database using a …

a)

Data Source Name (DSN) only

b)

A connection string only

c)

a Data Source Name (DSN) or a connection string

d)

none of the above is

correct


Q
28
.
The following SQL statement…

SELECT Name, Address, Title



FROM Book, Borrower, BorrowedBook



WHERE Borrower.ID = BorrowedBook.BorrowerID AND

Book.ISBN = BorrowedBook.BookID

a)

updates the BorrowedBook table

b)

deletes a record from the Book

and the Borrower tables

c)

Reads the name and address of a borrower and the title of the book borrowed
from the Book and Borrower tables of any book is borrowed.

d)

Reads the name and address of a borrower and the title of the book borrowed
from the Book and Bo
rrower tables of no book is borrowed.


Q
29
.
A disadvantage
(s)

of using a DSN is
/are
:

a)

If the connection string is stored as a parameter in the web.xml file then a
DSN connection is not appropriate.

b)

The connection information is stored in one place.

c)

The JSP
database connection code is simplified.

d)

All of the above


Q
30
.
Which is the incorrect ResultSet method used to access field data?

a)

rsName.getString("fieldname")

b)

rsName.getDouble("fieldname")

c)

rsName.getInt("fieldname")

d)

rsName.getAttribute("fieldname")









Page
6

of
10


Question
-
2









10 Marks


Write
a
one page

description
on one

of the following
:

1.

How Java Servlets are different from Java Server Pages (JSP)?




Java Servlets are Java classes whereas JSP scripts are a combination of HTML
and Java code



Java Servlets mu
st be compiled before execution whereas JSP code are not
required to be compiled



Java Servlets are more suitable for server side processing, data access, input
validations whereas JSP is more appropriate for displaying data or
presentation.



Java Servlets a
re more appropriate to be developed by software engineers
whereas JSP is more appropriate to be developed by a web designer



Java Servlets represent the ‘control’ in the MVC pattern whereas JSP
represents the ‘view’.



In Java Servlets all objects should be e
xplicitly created whereas in JSP implicit
objects are available (ex: session, out, request, etc.)


Example codes:



2.

Briefly explain the different techn
iques

you learnt in this subject to overcome
the problem of HTTP protocol being a stateless protocol.




I
ncluding forms in the generated pages, with data placed in fields (often
hidden)

Example:

out.println ("<form method=
\
"GET
\
" action =
\
"http://athene.csu.edu.au/names.cgi
\
">");

out.println ("<input type=
\
"hidden
\
" name=
\
"family_name
\
"
value=
\
"Dalgarno
\
">")
;

out.println ("<input type=
\
"submit
\
" value=
\
"OK
\
" name=
\
"B1
\
">");

out.println ("</form>");

In the above code family name is given as a ‘hidden’ data item.

When the form is
submitted it is passed to the web server.




Placing links to the script in genera
ted pages, with the data placed as a
parameter

Example

out.println ("<a href =" +


"
\
"http://athene.csu.edu.au/names.cgi?family=Smith
\
"");

out.println ("Click here");

out.println ("</a>");


In this example the data item family with the value ‘Smith’ is pas
sed as URL
parameter that is given just after the ? mark.




Page
7

of
10




Cookies


This is another alternative to the problem of statelessness. Cookies are small name
value pairs used at the client side. Cookies are generally used to store user name and
password of a u
ser that is used for server side authentication before user is gran
t
ed
access to the server side resources.


Example:


Setting a cookie to a response object.

response.setHeader("Set
-
Cookie","nationality=Indian");


reading cookie values

String nation;

Cook
ie[] cookies = request.getCookies();

for (int i=0; i<cookies.length; ++i)


if (cookies[i].getName().equals("nationality"))


nation=cookies[i].getValue();




Session objects

This is the Java solution for the above problem. Java session objects are base
d on
Cookies.


Example:


The creation of a session object is done as follows:

HttpSession session=request.getSession(true);

Setting and reading the attribute values in a session object is done as follows:

session.setAttribute("nationality","Indian");

Stri
ng nation=session.getAttribute("nationality");


3.

Write an introduction to Java Beans by including answers to the following
questions. What are Java Beans? What are the advantages of using Java Beans?
What are the advantages of JSP Tag libraries over Java Be
ans?


The use of Java Beans in conjunction with our JSP pages can allow us to separate the
business logic from the presentation

that leads to 3
-
tier architecture.
The Java Bean
will contain the data that we want to present to the user
.
The JSP page contain
s little
or no Java code, but instead just presentation code and code to retrieve the properties
of the Bean
.


A Java Bean is simply an instance of a Java class which encapsulates a series of data
items (properties)
.
Any Java class which satisfies the fol
lowing constraints can be
used as a Bean class:



It must contain a default constructor, that is a constructor with no parameters



Access to attributes must be through getter and setter methods, which must be
named getSomething or setSomething



We refer to the

values that can be get or set as the properties of the bean (they
don't always have to correspond exactly to the attributes of the Bean)



Page
8

of
10


Example:

public class BookmarkBean

{


private String title, url, description;




public BookmarkBean () {


}


public void setTitle (String title) {


this.title = title;


}


public String getTitle () {


return title;


}


public void setUrl (String url) {


this.url = url;


}


public String getUrl () {


return url;


}


public void setDescription (String description) {


this.description = description;


}


public String getDescription () {


return description;


}

}

We construct the Bean object just as we would an instance of any Java class:

Bo
okmarkBean bookmark = new BookmarkBean();

We can then call the Bean’s setter methods to set its attributes:

bookmark.setTitle(“ABC Online”);

bookmark.setUrl(“abc.net.au”);


Question
-
3









15 Marks


Write a

S
ervlet to
create a connection to a customer d
atabase using the DSN,
customerDSN and
read
all details in a table named customer and display them as a
web page on a web browser. The customer table includes: custNo (the primary key),
custFirstName, custLastName,
dateJoined
. All these table fields are te
xt

except the
dateJoined that is of Date type
.



import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

import java.sql.*;


public class CustomerControllerServlet extends HttpServlet{


Connection
connCustomers
;


private ServletConfig
config;


Page
9

of
10


public void init(ServletConfig config)


throws ServletException{


this.config=config;


}


public void service (HttpServletRequest req, HttpServletResponse res)

throws ServletException, IOException {


//create a session object if one does not

exists


HttpSession session = req.getSession(true);


res.setContentType("text/html");


PrintWriter out = res.getWriter();



//create a connection object


Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();


Connection conn
Customers

=
Dri
verManager.getConnection("jdbc:odbc:
customerDSN
");


String sql
Customers

= "SELECT * FROM
customer
";


Statement stmtCustomers

= conn
Customers
.createStatement();


ResultSet rs
Customer
s = stmtTennis.executeQuery(sql
Customers
);


//Creating a HTML page with

customer details


out.println ("<HTML>”)
;


out.println ("<HEAD>”)
;


out.println ("<TITLE>Customer Details</TITLE>”)
;


out.println ("<BODY>”)
;


out.println ("<TABLE>”)
;


out.println ("<tr> <td>Customer No</td><td>First Name</td><td>Last
Name</td><td>
Date Joined</td></tr>”)
;


//read data from the ResultSet object


while (rs
Customer
s.next())


out.println ("<tr><td>" + rs
Customer
s.getString("
custNo
") +"</td><td>" +
rs
Customers.getString("custFirstName
")+"</td><td>" +
rsCustomers.getString("custLast
Name
") +"</td><td>" +
rsCustomers.getString("
dateJoined
") +"</td></tr>");

//close the ResultSet and connection objects

stmtCustomers.close();

rsCustomers.close();

connCustomers.close();


out.println ("<
/
TABLE>”)
;


out.println ("<
/
BODY>”)
;


out.println (
"</HTML>”)
;

}

}


//use the following code if data is read from a Bean and send a redirect to a JSP



//read the record and store in a CustomerBean Object


CustomerBean CustomerBean= new CustomerBean(); //creates a new
CustomerBean object.

Page
10

of
10



Custome
rBean.setCustNo(rsCustomer.getString("custNo"));


CustomerBean.setCustFirstName(rsCustomer.getString("custFirstName"));


CustomerBean.setCustLastName(rsCustomer.getString("custLastName"));


//CustomerBean.setDateJoined(rsCustomer.getString("dateJoine
d"));



//store CustomerBean object in the session object


session.setAttribute("CustomerBean", CustomerBean);



//redirect to the JSP for displaying Customer details


res.sendRedirect("/displayCustomer.jsp");


Question
-
4









15 Marks


Write
a
on
e page

description
about
one

of the below technologies
that you did not
study in this subject yet related
to
the
web applications.


1.

J
SON Objects

2.

Web 2

3.

HTML 5


Question
-
5

(An Additional Question)





15 Marks


Write a
JSP code to display the customer detai
ls (custNo, custFirstName,
custLastName,
dateJoined
) form a Java Bean that is available in a session object and
display them as a web page on a web browser. Consider the name of the bean that
holds customer details as CustomerBean.


<%@ page import="Custom
erBean"%>

<html><head><title>Customer Display</title></head>

<body>

<h3>Customer Display</h3>

<jsp:useBean id="customer" scope="session" class="CustomerBean"/>

<p>

<a href="<jsp:getProperty name="customer" property="custNo"/>">

<jsp:getProperty name="custo
mer" property="
custF
irstName"/></a><br>

<jsp:getProperty name="customer" property="
custL
astName"/></a><br>

<jsp:getProperty name="customer" property="dateJoined"/><br>

</p>

</body>

</html>