Anda di halaman 1dari 25

B.E/B.

Tech DEGREE EXAMINATION Nov/Dec 2007

Seventh semester
                                   
Computer Science and Engineering

CS 1401 - Internet Programming

(Regulation 2004)

Time: 3 hours                                                                Maximum marks: 100

Answer ALL questions

PART A (10 x 2 =20 marks)

1.What is the primary function of an HTTP server?

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.

2.What is the difference between an absolute pathname and a realative pathname?

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:

/group51/Smith/images/aliens.jpg is an absolute pathname.

images/aliens.jpg is a relative pathname.

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;

The value of double result=12.0;

(b).result=num1+++++num2;

The value of double result=12.0

The value of int result=19;

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.

5. What is the benefit of using Java script code in an HTML document?

Benefit of using Java script code in an HTML document

 Clean, lightweight and extremely fast loading.


 Familiar interface allows to jumpstart
 Easy to learn and use.
 All essential code editing features are right at their place.
 Fully customizable text editor, menus, toolbars, shortcut keys.
 Efficiently reuse common code fragments.

6. For the following form, write down the Javascript code to swap the contents of the two text
boxes

Code to swap the contents of the two textboxes


<html>
<head>
<script type="text/javascript">
                  function swap (A, B) {
                  alert ("swap");
                  var temp=document.DAForm.A.value;
                  alert ("A"+temp);
                  document.DAForm.A.value=document.DAForm.B.value;
                  document.DAForm.B.value=temp;
                  }
</script>
</head>

<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.

alert () function can be used to create an alert popup dialog box.


 
Example
<html>

<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?

10. How can you create JDBC statement?

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)

5 Layers of the Internet


Computers on the Internet are connected by various networks. The complexity of networking is
addressed by dividing the Internet into many layers. The International Organization for
Standardization (ISO) developed a 7 layer network model (Application, Presentation, Session,
Transport, Network, Data Link and Physical layers) long before the Internet has gained
popularity. The 7 layer model has been revised to a 5 layer TCP/IP based Internet Model
(Application, Transport, Internet, Network, and Physical layers).
Application Layer Application layer defines generic available network applications or services
the Internet can support. See the table below for widely used network applications and the
corresponding network protocols.

 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:

 Establishment and termination of a connection to a communications medium.


 Participation in the process whereby the communication resources are effectively shared
among multiple users. For example, contention resolution and flow control.

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)

(b) Explain the concept of TCP data transmission (16)

TCP data transmission


 Connection Establishment and Termination
TCP provides a connection-oriented service over packet switched networks. Connection-
oriented implies that there is a virtual connection between two endpoints.3 There are three
phases in any virtual connection. These are the connection establishment, data transfer and
connection termination phases.
2.1 Three-Way Handshake
Connection Establishment
In order for two hosts to communicate using TCP they must first establish a connection by
exchanging messages in what is known as the three-way handshake. The diagram below depicts
the process of the three-way handshake.
Host A initiates the connection by sending a TCP segment with the SYN control bit set and an initial
sequence number (ISN) we represent as the variable x in the sequence number field.
At some moment later in time, Host B receives this SYN segment, processes it and responds with a TCP
segment of its own. The response from Host B contains the SYN control bit set and its own ISN
represented as variable y. Host B also sets the ACK control bit to indicate the next expected byte from
Host A should contain data starting with sequence number x+1.
When Host A receives Host B's ISN and ACK, it finishes the connection establishment phase by sending a
final acknowledgement segment to Host B. In this case, Host A sets the ACK control bit and indicates the
next expected byte from Host B by placing acknowledgement number y+1 in the acknowledgement
field.
Data Transfer
Once ISNs have been exchanged, communicating applications can transmit data between each other. A
simple TCP implementation will place segments into the network for a receiver as long as there is data
to send and as long as the sender does not exceed the window advertised by the receiver. As the
receiver accepts and processes TCP segments, it sends back positive acknowledgements, indicating
where in the byte stream it is. These acknowledgements also contain the "window" which determines
how many bytes the receiver is currently willing to accept. If data is duplicated or lost, a "hole" may
exist in the byte stream. A receiver will continue to acknowledge the most current contiguous place in
the byte stream it has accepted.
If there is no data to send, the sending TCP will simply sit idly by waiting for the application to put data
into the byte stream or to receive data from the other end of the connection.
If data queued by the sender reaches a point where data sent will exceed the receiver's advertised
window size, the sender must halt transmission and wait for further acknowledgements and an
advertised window size that is greater than zero before resuming.
Timers are used to avoid deadlock and unresponsive connections. Delayed transmissions are used to
make more efficient use of network bandwidth by sending larger "chunks" of data at once rather than
in smaller individual pieces.
Connection Termination
In order for a connection to be released, four segments are required to completely close a connection.
Four segments are necessary due to the fact that TCP is a full-duplex protocol, meaning that each end
must shut down independently.
TCP Connection Termination

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)

Program to determine the number of odd, even, zero digits


import java.io.*;
class BRReadLines {
public static void main (String args [])
throws IOException
{

                  Buffered Reader br = new Buffered Reader (new


                  InputStreamReader (System. in));
                  String str;
                  int digit, no;
                  int odd=0, even=0, zero=0;
                  str = br.readLine ();
                  System.out.println (str);

                  no=Integer.parseInt (str);


                        while (no > 0)
                        {
                                    digit=no % 10;
                                    no=no/10;
                                    System.out.println ("DIGIT"+digit);
                                                if(digit==0){
                                                zero++;
                                    }
                                    if (digit%2==0 && digit!=0){
                                                                        even++;
                                    }
                                    if (digit%2==1){
                                                                        odd++;
                                    }
                        }
                        System.out.println ("Number of Zero digits:” zero);
                        System.out.println ("Number of odd digits:” odd);
                        System.out.println ("Number of even digits:” even);
}
}

(or)

           

(b) What is the use of the applet? Explain its lifecycle with an example (16)
 

The Applet states are


Initialization State

                  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

1. Create objects needed by the Applet.


2. Setup initial values.
3. Load images or fonts.
4. Set up colors.
5. The initialization occurs only once in the applet’s life cycle.

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);
}
}

Compile this program and the .class file will be generated.


HTML file for HelloJavaProgram applet

<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

 width, the width of each stripe


 height, the height of each stripe
 colors, an array in which each element is the name of a color. Each color name is a valid
HTML, color (can be used as the value of a BGCOLOR attribute or CSS color property).
(16)

<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>

<body><FORM NAME="DAForm" method="get">


Input text1:<INPUT TYPE="TEXT" NAME="A">
Input text2:<INPUT TYPE="TEXT" NAME="B">
<input type="submit" name="but" onClick="asd(form)">

<TABLE BORDER="7" CELLPADDING="10" cellspacing="20" width='&{asd};'


height='&{dsa};'
bordercolor='&{randomrgb};'>
<TR bgcolor="#aa33dd">
<TD>This is a TD cell</TD>
<TD><PRE> </PRE></TD>
<TH>This is a TH cell</TH>
</TR>
<TR>
<TH VALIGN="TOP">Text aligned top</TH>
<TH>Image in TH cell with default alignments ---></TH>

</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.

Main Page with the advertisement


<html>
<head><title>Refer Our Web</title></head>
<frameset cols="80%,20%">

<frame name="f1" src="D:\html\homeyahoo.html" >


<frame name="f2" src="D:\html\advertise.html" >

<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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
           
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;</td>
                                                   <td><table border="1" cellspadding="1"><tr><td><h3><a
href="">&nbsp;&nbsp;Data&nbsp;&nbsp;</a></font></td>
                                                                                           <td><h3><a
href="">&nbsp;&nbsp;Image&nbsp;&nbsp;</a></font></td>
                                                                                           <td><h3><a
href="">&nbsp;&nbsp;Web&nbsp;&nbsp;</a></font></td>
                                           </table></td>
                                      </td></tr>
                                   
<tr><td><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
           
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;</td>
                                      <td>Search: <input type="text" method=""></td><td><input
type="submit" name=Search" value="Search"></td><tr>

            </table></td>

</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)

Program to display the image repeatedly in a file                                                   


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="css.css"
<link href="css.css" rel="stylesheet" type="text/css" />
</head>

<body background="1.jpg">
<?php
echo(date(" h:i:s A") . "<br />");

?>

</body>
</html>

CSS code to display the image repeatedly

.t1 { position: relative; text-shadow:#CC33FF; text-align: center;


                  font-family: Arial, Helvetica, sans-serif; width:100px;
text-transform: capitalize; text-decoration: blink; background-color:#CCCCFF;
                   background-position: center; table-layout: fixed; border: medium;
                   }
                   .t2
                   {
                   background-repeat:repeat;
                    }
                 
                   

.ts{ width:100% ; margin-left:50px; margin-right:50px; margin-bottom:50px; margin-top:50px;

(or)

(b) Describe the use of data binding and data control in DHTML (16)

Data Binding in Dynamic HTML

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.

Data binding in DHTML

<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>

<OBJECT id=tdcFile CLASSID="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83">


<PARAM NAME="DataURL" VALUE="file.csv">
<PARAM NAME="UseHeader" VALUE="True">
<param name="FieldDelim" value=";">
<param name="CaseSensitive" value="false">
</OBJECT>

<TR>
<TD COLSPAN=4><LABEL><B>Name:</B>&nbsp;</LABEL>
</TD>
</TR>

<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=2>


<TR BGCOLOR=#333366>
<TD><DIV ID='divDept'><FONT COLOR=#FFFFFF><B>All</B></FONT></DIV></TD>
<TR>
<TD>
<TABLE DATASRC="#tdcFile">
<THEAD>
<TR>
<TH BGCOLOR=#333366>Car</TH>
<TH BGCOLOR=#333366>Name</TH>
<TH BGCOLOR=#333366>Resp</TH>
<TH BGCOLOR=#333366>email</TH>
<TH BGCOLOR=#333366>doc</TH>
</TR>
</THEAD>
<TBODY>
<TR>
<TD BGCOLOR=#EEEECC><DIV datafld=car></DIV></TD>
<TD BGCOLOR=#EEEECC><DIV datafld=name></DIV></TD>
<TD BGCOLOR=#EEEECC><DIV datafld=resp></DIV></TD>
<TD BGCOLOR=#EEEECC><A DATAFLD=Email STYLE='Text-Decoration: None'
ONMOUSEOVER='if(this.href.indexOf("mailto:") == -1){ this.href = "mailto:" +
this.href};'><SPAN datafld=Email></SPAN></A></TD>
<TD BGCOLOR=#EEEECC><A DATAFLD=doc STYLE='Text-Decoration: None'
ONMOUSEOVER='if(this.href.indexOf("") == -1){ this.href = "" + this.href};'><SPAN
datafld=doc></SPAN></A></TD>

</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

<OBJECT ID="SomeID" CLASSID="CLSID: 333C7BC4-460F-11D0-BC04-0080C7055A83">


...
...
...
</OBJECT>
 

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.

Thus, an example complete initialization will look as follows :

<OBJECT ID="SomeID" CLASSID="CLSID:333C7BC4-460F-11D0-BC04-0080C7055A83">


<PARAM NAME="DataURL" VALUE="YourDataFile.txt">
<PARAM NAME="UseHeader" VALUE="TRUE">
<PARAM NAME="TextQualifier" VALUE="~">
<PARAM NAME="FieldDelim" VALUE="|">

</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.

Servlet Initialization: init method

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.

Servlet request handling

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

The ServletContext object defines a servlet’s view of the Web application


within which the servlet is running, and gives the servlet the ability to access resources that are
explicitly available to it. Using such an object, a servlet can log events, obtain URL references to
resources, and get and set attributes at the application level that are available to other servlets in
the same context, in much the same way as the set attributes at the request and session level.

5.ServletResponse

Each request is represented by a ServletRequest object and the corresponding response by a


ServletResponse object in the Java Servlet API.The ServletRequest interface to indicate whether
or not the request was transmitted via a secure transport such as HTTPS.

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)

Retrieving data from Internet


                  Internet Search Engines are used to locate resources in specific application content
area and thus download text and graphics from the Internet. Also download audio and video
resources from the Internet.
Search Engines are used to find materials and research related information. Search Engines are
accessed by pointing the www browser to the address of the search engine. The search engine
will provide a blank text field into which, we type one or more keywords indicating what we
want.

Retrieving Pictures, Sounds and Movies


                  Alta Vista not only download text but it can download images, video, audio based on
searching given by the user. The quickest way to download text from the Internet is to copy the
text on to the window clipboard, from which user can paste the text into any other window on
the screen.
                  The quickest way to download a graphic from the Internet is to use, web browser’s
option for saving the image to a file.
Downloading Audio and Video from the Internet
                  If the web browser supports the option to download links, download any audio or
video file that has been linked to a webpage.
HTTP Protocol:
                  The Hyper Text Transfer Protocol (HTTP) is an application-level protocol with
lightness and speed necessary for distributed, collaborative, Hyper-media information systems.
HTTP has been in used by the World Wide Web global information.
                  HTTP is also used as a generic protocol for communication between user agents and
proxies/Gateways to other Internet protocols, such as SMTP, NNTP, FTP, Gopher and WAIS,
allowing basic hypermedia access to resources available from diverse application and
simplifying the implementation of user Agents.
Overall Operation

The HTTP protocol is based on a request/response paradigm. A client establish a connection


with a server and sends a request to the server in the form a request method, URI and protocol
version, followed by a MIME-like message containing request modifiers, client information and
possible body content. The server response with a status line, including the messages protocol
version and a success or error code, followed by a MIME like message containing server
information, Entity meta information and possible body content.
                  Most HTTP communication is initiated by the user agent and consists of a request to
be applied to a resource on some origin server. In the simplest case, this may be accomplished
via a single connection (v) between the user agent (UA) and the origin
Server (O).

HTTP Request Response Chain


            A more complicated situation occurs when one or more intermediaries are present in the
request/response chain. The are three common forms of intermediary: proxy, gateway, and
tunnel.

            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.

Uniform Resource Identifiers

            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

If the port is empty or not given, port 80 is assumed.

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.

Anda mungkin juga menyukai