Beruflich Dokumente
Kultur Dokumente
Seventh semester
Computer Science and Engineering
(Regulation 2004)
HTTP servers provide function that monitors a URL that is part of the web site (for example, your home
page) and will take recovery action if the web server is no longer serving the web content. For example,
the monitor function will try to end and start the web server or may initiate a switch-over to move the
HTTP server function to the backup node in the cluster.
Absolute pathnames are similar to file references, but rather than referring to a file on your
computer, they refer to a file on the web server. Absolute references will always start with a
single slash—/—or http://. Whereas the relative pathnames are relative to the location of the file
that contains them. Relative pathnames are typically shorter than the other two types.
Example:
3. For each of the following, write down the value that will be stored in result
double result;
int num1=5,num2=12,num3=2;
double val1=5.0,val2=12.0,val3=2.0;
(a).result=num1*num3*4%num2/val3;
(b).result=num1+++++num2;
4.What is an important difference between writing a Java application and a Java Applet?
1. An applet runs under the control of a browser, whereas an application runs stand-alone, with
the support of a virtual machine. As such, an applet is subjected to more stringent security
restrictions in terms of file and network access, whereas an application can have free reign over
these resources.
2. Applets are great for creating dynamic and interactive web applications, but the true power of Java
lies in writing full blown applications. With the limitation of disk and network access, it would be
difficult to write commercial applications (though through the user of server based file systems, not
impossible). However, a Java application has full network and local file system access, and its potential
is limited only by the creativity of its developers.
6. For the following form, write down the Javascript code to swap the contents of the two text
boxes
<FORM NAME="DAForm">
<body>
Input text1 :< INPUT TYPE="TEXT" NAME="A">
Input text2 :< INPUT TYPE="TEXT" NAME="B">
<input type="button" name="but" onClick="swap (A, B)">
</body>
</FORM>
</html>
7. Which function can be used to create an alert popup dialog box? Write an example to create
an Alert popup box.
<head>
<script type="text/javascript">
function compute ()
{
alert ("Enter the phone no");
</script>
</head>
<form >
<body>
Enter the Text<input type="text" name="telno">
<input type="submit" value="Calculate" onClick="compute ()">
</body>
</form>
</html>
8. State the commands in cascading style sheet used for grouping of elements.
9. What is servlet? How do you compare servlet and traditional CGI programs?
PART B (5 x 16 = 80)
11.(a) List the five layers used by the Internet. For each layer you list, give the general purpose
of each layer as well as a current implementation (16)
Protocol
Application
Web HTTP
Email SMTP
File Transfer FTP
Application layer is the top layer of the OSI (Open System Interconnectivity) server layer
model. This layer handles issues like network transparency, resource allocation and problem
partitioning. The application layer is concerned with the user's view of network (e.g. formatting
electronic mail messages). The presentation layer provides the application layer with a familiar
local representation of data independent of the format used on the network.
The application layer provides the interface to the communications environment which is used
by the application process. It is responsible for communicating application process parameters.
Application layer falls under the "host layers" in the OSI topologies used in network
communication and it is also the top layer in the Internet model. The host layer also provide for
accurate delivery of data between computers in the network.
Transmission Control Protocol (TCP) Layer This layer concerns how data can be reliably
transferred over the network. UDP (User Datagram Protocol) is used when speed of data
transmission is more important than reliability.
The Transport Layer provides transparent transfer of data between end users, providing reliable
data transfer services to the upper layers. The transport layer controls the reliability of a given
link through flow control, segmentation/desegmentation, and error control. Some protocols are
state and connection oriented. This means that the transport layer can keep track of the segments
and retransmit those that fail.
Internet Protocol (IP) Layer This layer handles address and routing of the network. The
Network Layer provides the functional and procedural means of transferring variable length data
sequences from a source to a destination via one or more networks, while maintaining the
quality of service requested by the Transport Layer. The Network Layer performs network
routing functions, and might also perform fragmentation and reassembly, and report delivery
errors. Routers operate at this layer—sending data throughout the extended network and making
the Internet possible. This is a logical addressing scheme – values are chosen by the network
engineer. The addressing scheme is hierarchical.
The best-known example of a Layer 3 protocol is the Internet Protocol (IP). It manages the
connectionless transfer of data one hop at a time, from end system to ingress router, to router to
router, and from egress router to destination end system. It is not responsible for reliable
delivery to a next hop, but only for the detection of errored packets so they may be discarded.
When the medium of the next hop cannot accept a packet in its current length, IP is responsible
for fragmenting into sufficiently small packets that the medium can accept it.
Local Network Access Protocol (NAP) Layer This is the part of your system that is concerned
with how you communicate with your local network, whether is Ethernet or token ring. The
Data Link Layer provides the functional and procedural means to transfer data between network
entities and to detect and possibly correct errors that may occur in the Physical Layer.
Originally, this layer was intended for point-to-point and point-to-multipoint media,
characteristic of wide area media in the telephone system. Local area network architecture,
which included broadcast-capable multiaccess media, was developed independently of the ISO
work, in IEEE Project 802. IEEE work assumed sublayering and management functions not
required for WAN use. In modern practice, only error detection, not flow control using sliding
window, is present in modern data link protocols such as Point-to-Point Protocol (PPP), and, on
local area networks, the IEEE 802.2 LLC layer is not used for most protocols on Ethernet, and,
on other local area networks, its flow control and acknowledgment mechanisms are rarely used.
Sliding window flow control and acknowledgment is used at the transport layers by protocols
such as TCP, but is still used in niches where X.25 offers performance advantages.
Physical Layer This is the physical connection whether using a Network Interface Card (NIC)
or with a modem to connect to the local network. The Physical Layer defines all the electrical
and physical specifications for devices. In particular, it defines the relationship between a device
and a physical medium. This includes the layout of pins, voltages, cable specifications, Hubs,
repeaters, network adapters, Host Bus Adapters (HBAs used in Storage Area Networks) and
more.
To understand the function of the Physical Layer in contrast to the functions of the Data Link
Layer, think of the Physical Layer as concerned primarily with the interaction of a single device
with a medium, where the Data Link Layer is concerned more with the interactions of multiple
devices (i.e., at least two) with a shared medium. The Physical Layer will tell one device how to
transmit to the medium, and another device how to receive from it (in most cases it does not tell
the device how to connect to the medium). Obsolescent Physical Layer standards such as RS-
232 do use physical wires to control access to the medium.
The major functions and services performed by the Physical Layer are:
Modulation, or conversion between the representation of digital data in user equipment and the
corresponding signals transmitted over a communications channel. These are signals operating
over the physical cabling (such as copper and optical fiber) or over a radio link.
(or)
Notice that instead of SYN control bit fields, the connection termination phase uses the FIN control bit
fields to signal the close of a connection.
To terminate the connection, the application running on Host A signals TCP to close the connection. This
generates the first FIN segment from Host A to Host B. When Host B receives the initial FIN segment, it
immediately acknowledges the segment and notifies its destination application of the termination
request. Once the application on Host B also decides to shut down the connection, it then sends its own
FIN segment, which Host A will process and respond with an acknowledgement.
12.(a) Write a program in Java that determines and prints the number of odd, even and zero
digits in an integer value read from the keyboard (16)
(or)
(b) What is the use of the applet? Explain its lifecycle with an example (16)
Applet enters the initialization state when it is first loaded. This is achieved by
calling the init() method of Applet class. The applet is born. At this stage, do the following
things, if required
Running State
Applet enters the running state when the system calls the start() method of Applet
class. This occurs automatically after the applet is initialized. Starting can also occur if the
applet is already in ‘stopped’ (idle) state.
Idle or Stopped State
An apple becomes idle when it is stopped from running. Stopping occurs
automatically when the page leaves the currently running applet. By calling the stop() method
explicitly a thread of an applet can be stopped.
Dead State
An applet is said to be dead when it is removed from memory. This occurs
automatically by invoking the destroy() method. Like initialization, destroying stage occurs only
once in the applet’s life cycle. If the applet has created any resources, like threads, the destroy()
method may be overridden to clean up these resources.
Display State
Applet moves to the display state whenever it has to perform some output operations
on the screen. This happens immediately after the applet enters into the running state. The
paint() method is called to accomplish this task.Almost every applet will have a paint() method.
Like other methods in the life cycle, the default version of paint() method does absolutely
nothing. The programmer must override the method to display anything on the screen.
The paint() method is not considered as the part of the applet’s life cycle. The paint() method is
defined in the Applet class. It is inherited from the Component class, a super class of Applet.
Example program
import java.awt.*;
import java.applet.*;
public class HelloJavaProgram extends Applet{
String str;
Public void init()
{
str=getParameter (“String”);
if(str==null)
str=”Java”;
str=”Hello” + str;
}
public void paint(Graphics g)
{
g.drawString (str,10,100);
}
}
<html>
<head>
<title> Welcome to Java Applet </title>
</head>
<body>
<applet code=” HelloJavaProgram.class” width= 400 height=200>
<param name=”String” value=”Applet!”>
</applet>
</body>
</html>
Save this file as HelloJavaParam.html and then run applet using the applet viewer as follows:
appletviewer HelloJavaProgram.html
13.(a) Write a java script function named draw stripes that will draw a number of colored stripes
generating an HTML table in which each row has a (possibly) different color. Your function
must accept three parameters
<html>
<head>
<script type="text/javascript">
function asd(form)
{
var asd=form.A.value;
var dsa=form.B.value;
self.location='table.html?text1=&'asd+'text2=&'dsa;
}
</script>
</head>
</TR>
<TR>
<TH VALIGN="BOTTOM">Text aligned bottom</TH>
<TD><Image in TD cell with default alignments ---></TD>
</TR>
</TABLE></form>
</body>
</html>
(or)
(b)Explain how you could use HTML frames to provide a website that includes an
advertisement for your company along with the content from any other webpage. Show that
HTML you would need to do this, as you that for your example the “other webpage” is
WWW.yahoo.com. Make sure that you explain how this work.
<body>
</body>
</frameset>
</html>
Design of Yahoo webpage
<html>
<head><title>Yahoo Page</title>
<style type="text/css">
a:link{color:#0000ff}
a:visited{color:#0000ff}
a:active{color:#0000ff}
a:hover{color:#a0aeff}
</style>
</head>
<body><h1><font color="blue">Yahoo..</font></h1>
<table><tr>
<td><table><tr><td>
</td>
<td><table border="1" cellspadding="1"><tr><td><h3><a
href=""> Data </a></font></td>
<td><h3><a
href=""> Image </a></font></td>
<td><h3><a
href=""> Web </a></font></td>
</table></td>
</td></tr>
<tr><td><br><br> &nb
sp;
</td>
<td>Search: <input type="text" method=""></td><td><input
type="submit" name=Search" value="Search"></td><tr>
</tr></table>
</body>
</html>
Advertisement Page
<html>
<head><title>Advertise Page</title></head>
<body>
<table><tr>
<td>
<img src="D:\html\fs.bmp">
</td>
</tr>
</table>
</body>
</html>
14(a) Write a program using Cascading Style Sheet (CSS) to display the background image
repeatedly in a file. (16)
<body background="1.jpg">
<?php
echo(date(" h:i:s A") . "<br />");
?>
</body>
</html>
(or)
(b) Describe the use of data binding and data control in DHTML (16)
Accessing data on the Internet using current technology is slow. Pages are slow to render
because they are being built by server processes. The processes building these pages are slowing
down the server because the server is generating HTML rather than transmitting files. Since, on
the client, the data in a page is indistinguishable from the page that contains it, additional
requests are made to the server to manipulate the data.
Data binding is a new feature of Microsoft® Internet Explorer 4.0 (IE 4.0) that enables authors
to create Web pages that are faster to render, more interactive, easier to author, and that require
fewer server resources. It does this by using the Dynamic HTML support built into IE 4.0.
Dynamic HTML allows all the elements on a Web page to be manipulated through scripting
languages. Data binding uses Dynamic HTML in conjunction with a simple declarative syntax
to display data using standard HTML elements without resorting to complex scripting. Instead
of the traditional method of merging the data with the HTML through server-side templates or
CGI scripts before it’s sent to the browser, data binding performs this operation on the client
after a page is received.
<HTML>
<HEAD>
<TITLE></TITLE>
<STYLE>
BODY { font-size: 9pt; font-family: verdana, tahoma, sans serif, helvetica; }
TH A { color: white }
TH A:Hover { color: yellow }
</STYLE>
</HEAD>
<BODY>
<TR>
<TD COLSPAN=4><LABEL><B>Name:</B> </LABEL>
</TD>
</TR>
</TR>
</TBODY>
<TFOOT>
</TFOOT>
</TABLE>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
DataControl
Tabular Data Control is a Microsoft ActiveX control that comes pre-installed with all versions
of IE4+. This useful control allows to access, display, and even sort ASCII information stored
on the server end, such as a .txt file. In other words, it creates a simple database function without
the need for server side scripting such as PHP and mySQL. A client side language such as
JavaScript handles the more sophisticated features of Tabular Data Control.
Implementation:
The ActiveX control is initialized using the <OBJECT> tag. The CLASSID (unique identifier)
for the tabular data control is
CLSID:333C7BC4-460F-11D0-BC04-0080C7055A83
Initialization of the Control
Any object, like applet, has a number of parameters. Parameters of the object are specified using
the <PARAM> tag. The tabular data control has around 8 parameters.
DataURL: The path of the file that contains the data. For eg "data.txt".
UseHeader: Specifies whether the first line of the data file should be used as reference names
for their respective fields below. If specified to false, use "Column1", "Column2" etc instead.
The default value is false.
TextQualifier: Specifies the optional character that surrounds a field.
FieldDelim: Specifies the character that is used to separate each field in the data file. The
default character is the comma (,). For eg, consider a data file where we have the fields data:
*SomeName*|*SomeAge*|*SomeSex*. Here, the field delimiter used is '|' and '*' is the text
qualifier.
RowDelim: Specifies the character used to mark the end of each row of data. The default
character is the newline (NL) character.
</OBJECT>
The parameter names are not case sensitive. The Text Qualifier parameter is purely optional, though
can be useful in helping you more easily distinguish between each data entry.
15. (a).Explain Java servlet life cycle and interfaces in detail (16)
Servlet life-cycle
A client of a servlet-based application does not usually communicate directly with a servlet, but
requests the servlet’s services through a Web server or application server that invokes the servlet
through the Java Servlet API. The server’s role is to manage the loading and initialization of the
servlet, the servicing of the request, and the unloading or destroying of the servlet. This is
generally provided by a servlet manager function of the application server.
The only hard and fast rule is that a servlet engine must conform to the following life cycle
contract:
1. Create and initialize the servlet.
2. Handle zero or more service calls from clients.
3. Destroy the servlet and then garbage collects it.
The life cycle of a servlet is expressed in the Java Servlet API in the init, service (doGet or
doPost), and destroy methods of the Servlet interface.
Servlets can be dynamically loaded and instantiated when their services are first requested, or
the Web server can be configured so that specific servlets are loaded and instantiated when the
Web server initializes. In either case, the init method of the servlet performs any necessary
servlet initialization, and is guaranteed to be called once for each servlet instance, before any
requests to the servlet are handled. An example of a task which may be performed in the init
method is the loading of default data parameters or database connections.
The most common form of the init method of the servlet accepts a ServletConfig object
parameter. This interface object allows the servlet to access name/value pairs of initialization
parameters that are specific to that servlet. The ServletConfig object also gives us access to the
SevletContext object that describes information about our servlet environment.
Once the servlet has been properly initialized, it may handle requests (although it is possible that
a loaded servlet may get no requests). Each request is represented by a ServletRequest object and
the corresponding response by a ServletResponse object in the Java Servlet API.
The HttpServletRequest object encapsulates information about the client request, including
information about the client’s environment and any data that may have been sent from the client
to the servlet. The HttpServletRequest class contains methods for extracting this information
from the request object.
The HttpServletResponse is often the dynamically generated response, for instance, an HTML
page which is sent back to the client. It is often built with data from the HttpServletRequest
object. In addition to an HTML page, a response object may also be an HTTP error response, or
a redirection to another URL, servlet, or JavaServer Page.
Each time a client request is made, a new servlet thread is spawned which services the request.
In this way, the server can handle multiple concurrent requests to the same servlet. For each
request, usually the service, doGet, or doPost methods will be called. These methods are passed
the HttpServletRequest and HttpServletResponse parameter objects.
doPost: Invoked whenever an HTTP POST request is issued through an HTML form. The
parameters associated with the POST request are communicated from the browser to the server
as a separate HTTP request. The doPost method should be used whenever modifications on the
server will take place.
doGet: Invoked whenever an HTTP GET method from a URL request is issued, or an HTML
form. An HTTP GET method is the default when a URL is specified in a Web browser. In
contrast to the doPost method, doGet should be used when no modifications will be made on the
server, or when the parameters are not sensitive data. The parameters associated with a GET
request are appended to the end of the URL, and are passed into the Query String property of the
HttpServletRequest.
Destroy
The destroy method is called when the Web server unloads the servlet. A subclass of
HttpServlet only needs to implement this method if it needs to perform cleanup operations, such
as releasing database connections or closing files.
Interfaces used in Servlet Life Cycle are
1. Servlet
The Servlet interface class is the central abstraction of the Java Servlet API.
This class defines the methods which servlets must implement, including a service () method for
the handling of requests. The GenericServlet class implements this interface, and defines a
generic, protocol-independent servlet.
2. HttpServlet
HttpServlet provides additional methods for the processing of HTTP requests such as GET
(doGet method) and POST (doPost method).
3. ServletConfig
The most common form of the init method of the servlet accepts a ServletConfig object
parameter. This interface object allows the servlet to access name/value pairs of initialization
parameters that are specific to that servlet. The ServletConfig object also gives us access to the
SevletContext object that describes information about our servlet environment. A method of the
ServletConfig object allows to extract the parameter information from this object.
4.ServletContext
5.ServletResponse
6. ServletResponse
The output from the JSP is written directly to the ServletResponse Print Writer object.
(or)
(b).Describe the operation of retrieval of a webpage with its associated messages using HTTP.
(16)
A proxy is a forwarding agent; receiving requests for a URI in its absolute form,
rewriting all are parts of the message, and forwarding the reformatted request toward the server
identified by the URI.
A gateway is a receiving agent, acting as layer above some other servers and, if
necessary, translating the requests to the underlying server’s protocol.
A tunnel acts as a relay point between two connections without changing the messages;
Tunnels are used when the communication needs to pass through an intermediary (such as
firewall) even when the intermediary cannot understand the contents of the messages.
URIs have been known by many names: WWW addresses, Universal Document
Identifiers, Universal Resource Identifiers and finally the combination of Uniform Resource
Locators(URL) and Names(URN).As far as HTTP is concerned, Uniform Resource Identifiers
are simply formatted strings which identify—via name, location, or any other characteristic –a
network resource.
HTTP URL
The ‘http’ scheme is used to locate network resources via the HTTP protocol. This
sections defines the scheme-specific syntax and semantics for HTTP URLs.
http_URL=”http:” “//” host [“:” port ] [abs_path ]
host=<A legal Internet host domain name
or IP address (in dotted-decimal form),>
port=*DIGIT
Request-URI
The Request URI is a Uniform Resource Identifier and identifies the resource upon
which to apply the request.
Request-URI=absolute URI|abs_path
The two options for Request-URI are dependent on the nature of the request. The absolute URI form is
only allowed when the request is being made to a proxy. The proxy is requested to forward the request
and return the response. If the request is GET or HEAD and a prior response is catched, the proxy may
use the catched message if it process any restrictions in the Expires header fields. The proxy may
forward the request on to another proxy or directly to the server specified by the absolute URI. In order
to avoid request loops, a proxy must be able to recognize all of its server names, including any aliases,
local variations and the numeric IP address. An example request line would be:
GET http://www.w3.org/pub/www/theproject.html HTTP/1.10
Request Header Fields
The request header fields allow the client to pass additional information about a request, and
about the client itself, to the server. These fields act as request modifiers, with semantics equivalent to
the parameters on a programming language method (Procedure) invocation.
Response
After receiving and interpreting a request message, a server response in the form of an HTTP
response message.