Sie sind auf Seite 1von 27

KUVEMPU UNIVERSITY

Bsc(I.T)
WEB PROGRAMMING
CHITRANGADA CHAKRABORTY

Today, the Internet and intranets are exploding like wildfire. The article, "VISA Moves to IntranetSystem," in the January 29, 1996, issue of Information Week states that "two thirds of all large companieseither have an internal Web server installed or are thinking about it, and industry analysts believe that soon internal Web servers will outnumber external servers by a margin of 10 to 1. Forrester Research predicts the intranet server business will hit $1 billion by the year 2000." The daily announcements about new venture agreements, new application products, and new technology validate this prediction. In the nearly 30 years that I have worked in the computer industry, I cannot remember such an explosiveperiod.With all the excitement, one tends to forget that individuals laid the foundation for today's events in the late 1960s. The next three sections of this chapter look at the history, future, and fundamentals of the Internet, networks, and intranets. Then we devote four sections to the basics of TCP/IP networking. The chapter ends with a brief discussion of various applications, plug-ins, and applets.

Bsc(I.T) 2013
Kuvempu University

Subject: Web Programming Subject Code: BSIT - 52

Assignment: TA

1. What is the meaning of Web? Explain in detail the building elements of web
Web is a complex network of international , cross platform, and cross cultural communicating devices, connected to each other without any ordering or pattern. There are two most important building blocks of web: HTML and HTTP.

HTML: HTML stands for Hyper Text Markup Language HTML is a very simple language used to describe the logical structure of a document. Actually, HTML is often called programming language it is really not. Programming languages are Turing-complete, or computable. That is, programming languages can be used to compute something such as the square root of pi or some other such task. Typically programming languages use conditional branches and loops and operate on data contained in abstract data structures. HTML is much easier than all of that. HTML is simply a markup language used to define a logical structure rather tha n compute anything.

HTTP: HTTP is a request response type protocol. It is a language spoken between web browser (client software) and a web server (server software) so that can communicate with each other and exchange files. Page 2

WEB PROGRAMMING

Bsc(I.T) 2013
Now let us understand how client/server system works using HTTP. A client/server system works something like this: A big piece of computer (called a server) sits in some office somewhere with a bunch of files that people might want access to. This computer runs a software package that listens all day long to requests over the wires.

2. HTML is the Language of the Web Justify the statement


HTML is often called a programming language it is really not. Programming languages are Turing-complete, or computable. That is, programming languages can be used to compute something such as the square root of pi or some other such task. Typically programming languages use conditional branches and loops and operate on data contained in abstract data structures. HTML is much easier than all of that. HTML is simply a markup language used to define a logical structure rather than compute anything. For example, it can describe which text the browser should emphasize, which text should be considered body text versus header text, and so forth. The beauty of HTML of course is that it is generic enough that it can be read and interpreted by a web browser running on any machine or operating system. This is because it only focuses on describing the logical nature of the document, not on the specific style. The web browser is responsible for adding style. For instance emphasized text might be bolded in one browser and italicized in another. it is up to the browser to decide

3. Give the different classification of HTML tags with examples for each category LIST OF HTML TAGS :Tags for Document Structure HTML: <HTML> <BODY> This is a small HTML file. </BODY> </HTML> HEAD:
<HEAD> <TITLE> Mozilla speaks out</TITLE> <BASE HREF="http://www.mozilla.com"> </HEAD>

WEB PROGRAMMING

Page 3

Bsc(I.T) 2013
BODY:
<BODY BACKGROUND="bgURL" BGCOLOR="color" TEXT="color" LINK="color" ALINK="color" VLINK="color" ONLOAD="loadJScode" ONUNLOAD="unloadJScode" ONBLUR="blurJScode" ONFOCUS="focusJScode" CLASS="styleClass" ID="namedPlaceOrStyle" LANG="ISO" STYLE="style" > ... </BODY>

Heading Tags .TITLE: <html> <head> <title>HTML Reference</title> </head> <body> The content of the document...... </body> </html> BASE: <head> <base href="http://www.w3schools.com/images/" target="_blank"> </head> <body> <img src="stickman.gif" width="24" height="39" alt="Stickman"> <a href="http://www.w3schools.com">W3Schools</a> </body> META: <head> <meta name="description" content="Free Web tutorials"> <meta name="keywords" content="HTML,CSS,XML,JavaScript"> WEB PROGRAMMING Page 4

Bsc(I.T) 2013
<meta name="author" content="Stle Refsnes"> <meta charset="UTF-8"> </head> STYLE: <html> <head> <style type="text/css"> h1 {color:red;} p {color:blue;} </style> </head> <body> <h1>A heading</h1> <p>A paragraph.</p> </body> </html> LINK:

<head> <link rel="stylesheet" type="text/css" href="theme.css"> </head>


Block-Level Text Elements ADDRESS:
<ADDRESS> Netscape Communications Corporation<BR> 501 East Middlefield Road<BR> Mountain View, CA 94043<BR> </ADDRESS>

BLOCKQUOTE:
<BLOCKQUOTE> Bob Lisbonne, vice president of client product marketing at Netscape said: <BLOCKQUOTE> "Networked enterprises can begin to deploy Webtops as consistent corporate computing interfaces that span all platforms and can be updated dynamically." </BLOCKQUOTE> </BLOCKQUOTE>

DIV:
<DIV

WEB PROGRAMMING

Page 5

Bsc(I.T) 2013
ALIGN="LEFT"|"CENTER"|"RIGHT" CLASS="styleClass" ID="namedPlaceOrStyle" LANG="ISO" STYLE="style" >

H1 through H6:
<H1 <H2 <H3 <H4 <H5 ALIGN="LEFT"|"CENTER"|"RIGHT">...</H1> ALIGN="LEFT"|"CENTER"|"RIGHT">...</H2> ALIGN="LEFT"|"CENTER"|"RIGHT">...</H3> ALIGN="LEFT"|"CENTER"|"RIGHT">...</H4> ALIGN="LEFT"|"CENTER"|"RIGHT">...</H5> <H6 ALIGN="LEFT"|"CENTER"|"RIGHT">...</H6>

P:
<P ALIGN="LEFT"|"CENTER"|"RIGHT" CLASS="styleClass" ID="namedPlaceOrStyle" LANG="ISO" STYLE="style" > ... </P>

PRE: <pre> Text in a pre element is displayed in a fixed-width font, and it preserves spaces and line breaks </pre> Lists: DD: <dl> <dt>Coffee</dt> <dd>Black hot drink</dd> <dt>Milk</dt> <dd>White cold drink</dd> </dl> DIR: <dir> <li>html</li> <li>xhtml</li>

WEB PROGRAMMING

Page 6

Bsc(I.T) 2013
<li>css</li> </dir> DL: <dl> <dt>Coffee</dt> <dd>Black hot drink</dd> <dt>Milk</dt> <dd>White cold drink</dd> </dl> DT: <dl> <dt>Coffee</dt> <dd>Black hot drink</dd> <dt>Milk</dt> <dd>White cold drink</dd> </dl> LI: <ol> <li>Coffee</li> <li>Tea</li> <li>Milk</li> </ol> <ul> <li>Coffee</li> <li>Tea</li> <li>Milk</li> </ul> MENU: <menu type="toolbar"> <li> <menu label="File"> <button type="button" onclick="file_new()">New...</button> <button type="button" onclick="file_open()">Open...</button> <button type="button" onclick="file_save()">Save</button> </menu> </li> <li> <menu label="Edit"> <button type="button" onclick="edit_cut()">Cut</button> <button type="button" onclick="edit_copy()">Copy</button> <button type="button" onclick="edit_paste()">Paste</button> WEB PROGRAMMING Page 7

Bsc(I.T) 2013
</menu> </li> </menu> OL: <ol> <li>Coffee</li> <li>Tea</li> <li>Milk</li> </ol> <ol start="50"> <li>Coffee</li> <li>Tea</li> <li>Milk</li> </ol> UL: <ul> <li>Coffee</li> <li>Tea</li> <li>Milk</li> </ul> Text Characteristics B: <p>This is normal text - <b>and this is bold text</b>.</p> BASEFONT: <head> <basefont color="red" size="5" /> </head> <body> <h1>This is a heading</h1> <p>This is a paragraph.</p> </body> BIG: <html> <body> <p>This text is normal.</p> <p><big>This text is bigger.</big></p> WEB PROGRAMMING Page 8

Bsc(I.T) 2013
</body> </html> BLINK: <blink> blinking text tag</blink> CITE: <html> <body> <img src="img_the_scream.jpg" width="220" height="277" alt="The Scream"> <p><cite>The Scream</cite> by Edward Munch. Painted in 1893.</p> </body> </html> CODE: <html> <body> <em>Emphasized text</em><br> <strong>Strong text</strong><br> <dfn>Definition term</dfn><br> <code>A piece of computer code</code><br> <samp>Sample output from a computer program</samp><br> <kbd>Keyboard input</kbd><br> <var>Variable</var> </body> </html> EM: <html> <body> <em>Emphasized text</em><br> <strong>Strong text</strong><br> <dfn>Definition term</dfn><br> <code>A piece of computer code</code><br> <samp>Sample output from a computer program</samp><br> <kbd>Keyboard input</kbd><br> <var>Variable</var> </body> </html>

WEB PROGRAMMING

Page 9

Bsc(I.T) 2013
FONT: <html> <body> <p><font size="3" color="red">This is some text!</font></p> <p><font size="2" color="blue">This is some text!</font></p> <p><font face="verdana" color="green">This is some text!</font></p> </body> </html> I: <html> <body> <p>He named his car <i>The lightning</i>, because it was very fast.</p> </body> </html> KBD: <!DOCTYPE html> <html> <body> <em>Emphasized text</em><br> <strong>Strong text</strong><br> <dfn>Definition term</dfn><br> <code>A piece of computer code</code><br> <samp>Sample output from a computer program</samp><br> <kbd>Keyboard input</kbd><br> <var>Variable</var> </body> </html> PLAINTEXT: <HR> </BODY> <PLAINTEXT> >I have been following ... (Beginning lines of intended text) . . . (Concluding lines of intended text) ... especially in the biological sciences. Even fewer fundamentalists. WEB PROGRAMMING Page 10

Bsc(I.T) 2013
[snip] </PLAINTEXT> S: <p><s>My car is blue.</s></p> SMALL: <p><small>Copyright 1999-2050 by Refsnes Data</small></p>

4. Write CGI application which accepts 3 numbers from the user and displays biggest number using GET and POST methods
#!/usr/bin/perl #print "Content-type:text/html\n\n"; #$form = $ENV{'QUERY_STRING'}; use CGI; $cgi = new CGI; print $cgi->header; print $cgi->start_html( "Question Ten" ); my $one = $cgi->param( 'one' ); my $two = $cgi->param( 'two' ); my $three = $cgi->param( 'three' ); if( $one && $two && $three ) { $lcm = &findLCM( &findLCM( $one, $two ), $three ); print "LCM is $lcm"; } else { print ' '; print 'Enter First Number '; print 'Enter Second Number '; print 'Enter Third Number '; print ' '; print " "; } print $cgi->end_html;

WEB PROGRAMMING

Page 11

Bsc(I.T) 2013
sub findLCM(){ my $x = shift; my $y = shift; my $temp, $ans; if ($x < $y) { $temp = $y; $y = $x; $x = $temp; } $ans = $y; $temp = 1; while ($ans % $x) { $ans = $y * $temp; $temp++ ; } return $ans; }

5. What is JavaScript? Give its importance in web.


JavaScript is an easy to learn way to Scriptyour web pages that is have them to do actions that cannot be handled with HTML alone. With JavaScript, you can make text scroll across the screen like ticker tape; you can make pictures change when you move over them, or any other number of dynamic enhancement. JavaScript is generally only used inside of HTML document. i) JavaScript control document appearance and content. ii) JavaScript controls the browser. iii) JavaScript interacts with document content. iv) JavaScript interacts with the user. v) JavaScript read and write client state with cookies. vi) JavaScript interacts with applets. vii) JavaScript manipulate embedded images

6. Explain briefly Cascading Style Sheets


Cascading Style Sheet (CSS) is a part of DHTML that controls the look and placement of the element on the page. With CSS you can basically set any style sheet property of any element on an html page. One of the biggest advantages with the CSS instead of the regular way of changing the look of elements is that you split content from design.

WEB PROGRAMMING

Page 12

Bsc(I.T) 2013
You can for instance link a CSS file to all the pages in your site that sets the look of the pages, so if you want to change like the font size of your main text you just change it in the CSS file and all pages are updated. CSS controls the look and placement of elements on a page. With CSS you can set any style property of any element on a HTML page. One of the biggest advantages with CSS instead of regular way of changing the look of elements is that you can split content from design. You can, for instance, link a CSS file to all the pages in your site that sets the look of the pages. So if you want to change the elements on the page, such as font size of the main text, you can just change it in the CSS and all the pages will be updated. The syntax of CSS code is: <style type ="text/css"> ELEMENT [{property1:value1:property2:value2}] </style>

7. What is CGI? List the different CGI environment variables


CGI or Common Gateway Interface is a specification which allows web users to run program from their computer. CGI is a part of the web server that can communicate with other programs running on the server. With CGI, the web server can call up a program, while passing user specific data to a program. The program then processes that data and the server passes the programs response back to the web browser. When a CGI program is called, the information that is made available to it can be roughly broken into three groups:i). Information about client, server and user. ii). Form data that are user supplied. iii). Additional pathname information. Most Information about client, server and user is placed in CGI environmental variables. Form data that are user supplied is incorporated in environment variables. Extra pathname information is placed in environment variables.

i). GATEWAY_INTERFACE T he revision of the common Gateway interface that the server uses. ii). SERVER_NAME The Servers hostname or IP address. iii). SERVER_PORT The port number of the host on which the server is running. iv). REQUEST_METHOD The method with which the information request is issued. v). PATH_INFO Extra path information passed to the CGI program

WEB PROGRAMMING

Page 13

Bsc(I.T) 2013
vi)QUERY_STRING: The query information passed to the program. It is appended to the URL with a ? when the browser sends it to the server. The name value pairs are then stored in this environment variable. vii)SERVER_PROTOCOL: The name of and revision of the information protocol that the request came in with.. viii)HTTP_USER_AGENT: The browser used by the client to issue the request. xi)CONTENT_LENGTH: The length of the data in bytes passed to the CGI program through the standard input.

8. What is PERL? Explain PERl control structures with the help of an example
Perl is a programming language which can be used for a large variety of tasks. A typical simple use of Perl would be for extracting information from a text file and printing out a report or for converting a text file into another form. But Perl provides a large number of tools for quite complicated problems, including systems programming. Programs written in Perl are called Perl scripts, whereas the term the perl program refers to the system program named perl for executing Perl scripts If you have used shell scripts or awk or sed or similar (Unix) utilities for various purposes, you will find that you can normally use Perl for those and many other purposes, and the code tends to be more compact. And if you haven't used such utilities but have started thinking you might have need for them, then perhaps what you really need to learn is Perl instead of all kinds of futilities. Perl is implemented as an interpreted (not compiled) language. Thus, the execution of a Perl script tends to use more CPU time than a corresponding C program, for instance. On the other hand, computers tend to get faster and faster, and writing something in Perl instead of C tends to save your time.

PERL control structures include: 1. If-else and unless condition: This construct performs a Boolean test on an expression and performs actions based on the results of the Boolean test. For example: If($var==1) { $out = "This was one"; } elseif($var==0) { $out = "This was zero"; } else { $out = "Was neither 0 nor 1"; } print "$out"; The above code will print, "This was one" if the variable $var is 1. Otherwise, if $var is equal to 0, it will print "This was zero". If $var is nether 1 nor 0, it will print "Was neither 0 nor 1". Note that the

WEB PROGRAMMING

Page 14

Bsc(I.T) 2013
else or elesif part is optional. You can also have a single if statement in your program or nested ifs and if-else or if-elseif-else structures. Note that to compare strings you must use the eq operator. You can also join multiple conditions using the logical operators. Similar to the If command is the unless command. For example: unless($var!=1) { $out = "This was one"; } else { $out = "Not one"; } Note that PERL does not support unlessif. 2. Foreach loop: It is used for iterating over a list of values. The elements of an array can be iterated over using foreach as: Foreach my $i(@arr) { $arr[$i] = $i; //set the value of each element of array to its index number } 3. For loop: It is used to repeatedly perform an action. It uses a three-part conditional consisting of the loop initializer, the loop condition, and the loop reinitializer. For example, to perform an action such as printing use the for loop as: for($i=0;$i<10;$i++) { print "$i"; } This will print numbers from 0 to 9. 4. While loop: It is also used to perform an action repeatedly as long as a Boolean expression evaluates to true as: $i=0; while ($i<10) { print "$i"; } This will print numbers from 0 to 9. 5. Until loop: This performs the reverse action of the while loop. It executes as long as a Boolean expression is NOT true. For example: $i=0; until ($i>=10) { print "$i"; } This will print numbers from 0 to 9.

PART - A

WEB PROGRAMMING

Page 15

Bsc(I.T) 2013
I. Answer all the questions: a) What is the difference between Internet and Intranet?
Internet: Internet is global network of networks. Internet is a tool for collaborating academic research, and it has become a medium for exchanging and distributing information of all kinds. It is an interconnection between several computers of different types belonging to various networks all over global. Intranet: Intranet is not global. It is a mini web that is limited to user machines and software program of particulars organization or company

b) List any five HTML tags.


Five HTML tags are:i). UL (unordered list): The UL tags display a bulleted list. You can use the tags TYPE attribute to change the bullet style. ii). TYPE: defines the type of bullet used of each list item. The value can be one of the following-CIRCLE, DISC, and SQUARE iii). LI (list item): The LI tag indicates an itemized element, which is usually preceded by bullet, a number, or a letter. The LI is used inside list elements such as OL (ordered list) and UL (unordered list). iv). TABLES (table): The TABLE tag defines a table. Inside the TABLE tag, use the TR tag to define rows in the table, use the TH tag to define row or column headings, and the TD tag to define table cells. v). HTML (outermost tag): The HTML identifies a document as an HTML document. All HTML documents should start with the and end with the tags.

c) Write the difference between HTML and DHTML.


WEB PROGRAMMING Page 16

Bsc(I.T) 2013
HTML stands for Hypertext Markup Language DHTML is a Dynamic HTML. HTML is basically a markup language used for creating tags. But DHTML is not a language, DHTML is a web standard. Other major differences between HTML and DHTML are:

HTML

DHTML

HTML site work slowly upon client-side DHTML sites works faster upon clienttechnologies. side technologies

HTML is static in nature HTML files are saved with .htm extension

DHTML is dynamic in nature DHTML files are saved with .dhtm extension

HTML does not make use of any DHTML uses events, methods and methods for making it dynamic. HTML much more for providing dynamism for content is always static HTML pages HTML pages does not require any processing from browser DHTML requires processing from browser which changes its look and feel

d) Explain the different types of PERL variables.


PERL variables are of the following three types: Scalars: A scalar variable stores a single value of any type. Scalar variables are prefixed with a $. These variables need not be declared before using them. You can define or use a variable as: $var =1; $var_noval; $str = "This is a scalar string variable"; Arrays: Arrays store an ordered list of values. Arrays can be declared as: @emptyarr =(); @arr = ("1", "2","3"); Each individual item of an array is referred to by its index number as: print "$arr[0]"; You can use the push() and pop() functions to insert or delete an element from an array.

WEB PROGRAMMING

Page 17

Bsc(I.T) 2013
Hashes: A Hash is a special kind of an array - an associative array or paired list of elements. Each pair in a Hash consists of a string key and data value. A hash is defined as: %emptyhs = (); %hs = ("key1", "val1", "key2", "val2"); or %hs = (key1 => "val1", key2=> "val2"); An individual item of a Hash is referred to as $hs{"key1"}; The my function can be used with each of the above type of variables to declare and limit the scope of the variable to the enclosing block as: my $var;

e) How are JSPs better than servlets.


Unlike servlets, JSP lets you separate presentation and business logic. You can place the HTML code(presentation) in JSP along with some dynamic elements. The business logic remains in the servlets or JavaBeans. This approach helps to overcome the problems with a pure servlet based approach, such as: Thorough Java programming knowledge is needed to develop and maintain all aspects of the application, since the processing code and the HTML elements are lumped together. Changing the look and feel of the application, or adding support for a new type of client, requires the servlet code to be updated and recompiled. It is hard to take advantage of Web-page development tools when designing the application interface.

If such tools are used to develop the Web page layout, the generated HTML must then be manually embedded into servlet code. This process is time consuming and error prone.

PART - B II. Answer any FIVE full questions : 1. a) Explain GET and POST method with the help of an example. The GET Method
The foundation of HTTP/0.9 (the first implementation of the HTTP protocol) was the definition of the GET method that was used by a web browser to request a specific document. For example, the following HTTP request would return the document index.html that was located in the web servers root directory called webdocs. GET /webdocs/index.html CRLF Notice that the GET request began with the GET keyword, included a document to retrieve, and ended with a carriage return and line feed combination. Page 18

WEB PROGRAMMING

Bsc(I.T) 2013

If you would like, you can try making a GET request by connecting to your favorite web server and sending the GET request yourself (as if you were a web browser).

The Post Method


The POST method allows web browsers to send an unlimited amount of data to a web server by allowing them to tag it on to an HTTP request after the request headers as the message body. Typically, the message body would be our old familiar encoded URL string after the question mark (?). Thus, it would not be strange for a web server to get a POST request that looked something like the following: POST /cgi-bin/phone_book.cgi HTTP/1.0 Referrer: http://www.somedomain.com/Direcory/file.html User-Agent: Mozilla/1.22 (Windows: I: 32bit) Accept */* Content-type: application/x-www-form-urlencoded Content-length: 29 name=Selena+Sol&phone=7700404 Notice that the Content-length request header is equal to the number of characters in the body of the request. This is important because a CGI script could easily parse through the variables in the body using the length. Of course, as with the GET method, the user never needs to deal with the protocol itself. Instead, the browser does all the work of preparing the POST request headers and body.

b) Explain in detail the role played by CGI programming in web programming.


CGI opened the gates of more complex Web applications. It enabled developers to write scripts, which can communicate with server applications and databases. In addition, it enables developers to write scripts that could also parse client's input, process it, and present it in a user friendly way. The Common Gateway Interface, or CGI, is a standard for external gateway programs to interface with information servers such as HTTP servers. A plain HTML document that the Web daemon retrieves is static, which means it exists in a constant state: a text file that doesn't change. A CGI program, on the other hand, is executed in real-time, so that it can output dynamic information. CGI programming allows us to automate passing information to and from web pages. It can also be used to capture and process that information, or pass it off to other software (such as in an SQL database). CGI programs (sometimes called scripts) can be written in any programming language, but the two most commonly used are Perl and PHP.

WEB PROGRAMMING

Page 19

Bsc(I.T) 2013
Despite all the flashy graphics, Internet technology is fundamentally a text-based system. Perl was designed to be optimal for text processing, so it quickly became a popular CGI tool.

2. a)

With the help of an example explain the embedding of an image in an HTML tag.

To embed an image in an HTML page, you can use the <IMG> tag. The <IMG> tag includes various attributes, for embedding and formatting images in an HTML page. The most common attributes of the <IMG> tag are: SRC: Absolute or relative path of the image to be embedded LOWSRC: The path of the low resolution version the image ALT: Alternate text to be displayed in case the image cannot be loaded. ALIGN : Alignment of the image in the page HEIGHT: Height of the image WIDTH: Width of the image You can use the above tags to load an image from a URL or a relative path. For example, if the image (suppose image_filename.gif) that you want to embed resides in the same folder as the HTML page, you can embed it as: <IMG SRC="image_filename.gif" ALT = "this is an image loaded from a relative path"> The above will display the image in the file image_filename.gif. In case this image cannot be loaded, the text "this is an image loaded from a relative path" will be displayed. Similarly, to load an image from a URL, you can specify the URL in the SRC attribute. b) Create

a HTML page to demonstrate the usage of Anchor tags.

The following HTML page, demonstrates the usage of anchor tags: <html> <head> WEB PROGRAMMING Page 20

Bsc(I.T) 2013
<title>Anchor Tag Characteristics</title> </head> <body> <h1 align="center">All in One</h1> <p align="left">In <A HREF= "#sec1">section 1</a> you can search. In <A HREF= "#sec2">section 2</a> you can shop.</p> <A NAME= "sec1">Section 1: </a> <p> <a href="http://google.co.in" target= "_blank"> Search on Google</a>&nbsp;</p> <p><a href="http://yahoo.com">Search on Yahoo</a></p> <p>&nbsp;</p> <p> <A NAME= "sec2">Section 2: </a> </p> <p><a href="http://ebay.com"> Shop on ebay&nbsp;</a></p> <p><a href="http://wallpapers.com">Download wallpapers</a>&nbsp;</p> <p><a href="http://t-shirts.com"> Order Custom T-Shirts News</a></p> </body> </html> 3. a) Explain

the usage of script tags.

Using the SCRIPT Tag: The following example uses the SCRIPT tag to define a JavaScript script in the HEAD tag. The script is loaded before anything else in the document is loaded. The JavaScript code in this example defines a function, changeBGColor(), that changes the documents background color. The body of the document contains a form with two buttons. Each button invokes the changeBGColor() function to change the background of the document to a different color.

<HTML> <HEAD> <TITLE>Script Example</TITLE> </HEAD> <SCRIPT language="JavaScript"> function changeBGColor (newcolor) { WEB PROGRAMMING Page 21

Bsc(I.T) 2013
document.bgColor=newcolor; return false; } </SCRIPT> <BODY > <P>Select a background color:</P> <FORM> <INPUT TYPE="button" VALUE=blue onClick="changeBGColor('blue');"> <INPUT TYPE="button" VALUE=green onClick="changeBGColor('green');"> </FORM> <NOSCRIPT><I>Your browser is not JavaScript-enabled. These buttons will not work.</I> </NOSCRIPT> </BODY> </HTML>

b) What

is Java script? List the use of Java script.

JavaScript is a scripting language (like a simple programming language). It is a language that can be used for client-side scripting. JavaScript is only used inside of HTML documents. With JavaScript, we can make text scroll across the screen like ticker tape. The uses of JavaScript are: i). Control Document Appearance and Content ii). Control the Browser iii). Interact with Document Control iv). Interact with User v). Read and Write Client State with Cookies vi). Interact with Applets vii). JavaScript is only used inside of HTML documents

WEB PROGRAMMING

Page 22

Bsc(I.T) 2013
4. a) With the help of an example explain any five CGI environment variables.
i). SERVER_NAME : The server's host name or IP address. ii). SERVER_PORT : The port number of the host on which the server is running. iii). SERVER_SOFTWARE : The name and version of the server software that is answering the client request. iv). SERVER_PROTOCOL : The name and revision of the information protocol that request came in with. v). GATEWAY_INTERFACE : The revision of the common gateway interface that the server uses. Example:#!/usr/local/bin/perl print "Content-type: text/html", "\n\n"; print "<HTML>", "\n"; print "<HEAD><TITLE>About this Server</TITLE></HEAD>", "\n"; print "<BODY><H1>About this Server</H1>", "\n"; print "<HR><PRE>"; print "Server Name: ", $ENV{'SERVER_NAME'}, "<BR>", "\n"; print "Running on Port: ", $ENV{'SERVER_PORT'}, "<BR>", "\n"; print "Server Software: ", $ENV{'SERVER_SOFTWARE'}, "<BR>", "\n"; print "Server Protocol: ", $ENV{'SERVER_PROTOCOL'}, "<BR>", "\n"; print "CGI Revision: ", $ENV{'GATEWAY_INTERFACE'}, "<BR>", "\n"; print "<HR></PRE>", "\n"; print "</BODY></HTML>", "\n"; exit (0);

b) Write a CGI application which accepts three numbers from the used and display biggest number using GET and POST methods.
#!/usr/bin/perl

WEB PROGRAMMING

Page 23

Bsc(I.T) 2013
#print "Content-type:text/html\n\n"; #$form = $ENV{'QUERY_STRING'}; use CGI; $cgi = new CGI; print $cgi->header; print $cgi->start_html( "Question Ten" ); my $one = $cgi->param( 'one' ); my $two = $cgi->param( 'two' ); my $three = $cgi->param( 'three' ); if( $one && $two && $three ) { $lcm = &findLCM( &findLCM( $one, $two ), $three ); print "LCM is $lcm"; } Else { print ' '; print 'Enter First Number '; print 'Enter Second Number '; print 'Enter Third Number '; print ' '; print " "; } print $cgi->end_html; sub findLCM() { my $x = shift; my $y = shift; WEB PROGRAMMING Page 24

Bsc(I.T) 2013
my $temp, $ans; if ($x < $y) { $temp = $y; $y = $x; $x = $temp; } $ans = $y; $temp = 1; while ($ans % $x) { $ans = $y * $temp; $temp++ ; } return $ans; }

5. a) List the differences between web server and application server.


The main differences between Web servers and application servers : A Web server is where Web components are deployed and run. An application server is where components that implement the business logic are deployed. For example, in a JSP-EJB Web application, the JSP pages will be deployed on the Web server whereas the EJB components will be deployed on the application servers. A Web server usually supports only HTTP (and sometimes SMTP and FTP). However, an application server supports HTTP as well as various other protocols such as SOAP. In other word :- Difference between AppServer and a Web server :i). Web server serves pages for viewing in web browser, application server provides exposes business logic for client applications through various protocols ii). Web server exclusively handles http requests.application server serves business logic to application programs through any number of protocols. WEB PROGRAMMING Page 25

Bsc(I.T) 2013
iii). Web server delegation model is fairly simple, when the request comes into the webserver,it simply passes the request to the program best able to handle it(Server side program). It may not support transactions and database connection pooling. iv). Application server is more capable of dynamic behavior than web server. We can also configure application server to work as a webserver.Simply application server is a superset of web server.

b) What is a war file? Explain its importance.


WAR or Web Application Archive file is packaged servlet Web application. Servlet applications are usually distributed as a WAR files. A WAR file may be digitally signed in the same way as a JAR file in order to allow others to determine what source the code came from. There are special files and directories within a WAR file. The /WEB-INF directory in the WAR file contains a file named web.xml which defines the structure of the web application. If the web application is only serving JSP files, the web.xml file is not strictly necessary. If the web application uses servlets, then the servlet container uses web.xml to ascertain to which servlet a URL request will be routed. web.xml is also used to define context variables which can be referenced within the servlets and it is used to define environmental dependencies which the deployer is expected to set up. An example of this is a dependency on a mail session used to send email. The servlet container is responsible for providing this service. Advantages of WAR files:

easy development, testing and deployment the version of the deployed application is easily identified all Java EE containers support .WAR files

One disadvantage of web deployment using WAR files in very dynamic environments is that minor changes cannot be made during runtime. Any change whatsoever requires regenerating and redeploying the entire WAR file. The following sample web.xml file demonstrates how a servlet is declared and associated. <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" WEB PROGRAMMING Page 26

Bsc(I.T) 2013
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd"> <web-app> <servlet> <servlet-name>HelloServlet</servlet-name> <servlet-class>mypackage.HelloServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>HelloServlet</servlet-name> <url-pattern>/HelloServlet</url-pattern> </servlet-mapping> <resource-ref> <description> Resource reference to a factory for javax.mail.Session Instances that may be used for sending electronic mail messages, Preconfigured to connect to the appropriate SMTP server. </description> <res-ref-name>mail/Session</res-ref-name> <res-type>javax.mail.Session</res-type> <res-auth>Container</res-auth> </resource-ref> </web-app>

WEB PROGRAMMING

Page 27

Das könnte Ihnen auch gefallen