You are on page 1of 0

Page 1of 35 52.

WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
Ku v e m p u U n i v e r s i t y
Question Bank for B.Sc.(IT) 5
th
Sem
( Year 2006 2009 )
Page 2of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
Interact with user
Read and write client state with cookies
Interact with applets
Manipulate embedded images
4. What are the difference between HTML and DHTML?
HTML is a markup language used to create static web pages. DHTML on the other hand is not a
language by itself but a combination of different technologies such as HTML, CSS, J avaScript,
and DOM. It is used to create dynamic pages.
5. What are text nodes?
If a node contains text, it is represented as a text node. For example, in<p id-node2>"This is the
<b>initial</b>text.</p>, there are text nodes "This is the", "initial", and "text".
6. What is CGI? Give examples of CGI application.
Common Gateway Interface is a specification, which allows Web users to run programs from
their computers. CGI is not a programming language but rather a specification that allows
programs and scripts written in other language to be run over the Internet.
7. What is Query String?
The query information passed to the program. It is appended to the URL with a QUERY_STRING:
? when the browser sends it to the server. The name value pairs are then stored in this
environment variable.
8. What is Extra Path Information?
Besides passing query information to a CGI script, you can also pass additional data known as
extra path information as part of the URL. The server gauges where the CGI program name
ends; anything following that is deemed as extra path information and stored in the PATH_INFO
environment variable. For example the following line calls a script with extra path information:
http://some.machine/cgi0bin/display.pl/cgi_doc.txt
9. What is a web server?
The Web server is the software responsible for accepting browsers' requests, retrieving the
specified file or executing the script, and returning its content to the browser. Popular Web
servers include Tomcat, Apache, and IIS.
10. List out differences between web server and application server.
The main differences between Web servers and application servers are:
Page 3of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
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 J SP-EJ B Web
application, the J SP pages will be deployed on the Web server whereas the EJ B 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
(1) Webserver serves pages for viewing in web browser, application server provides exposes
businness logic for client applications through various protocols
(2) Webserver exclusively handles http requests.application server serves bussiness logic to
application programs through any number of protocols.
(3) Webserver 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.
(4) Application server is more capable of dynamic behaviour than webserver. We can also
configure application server to work as a webserver.Simply applic! ation server is a superset of
webserver.
11. Describe role of deployment descriptors.
A deployment descriptor is an XML document that defines all the components of an application
along with related information such as initialization parameters and container managed security
constraints that you want the server to enforce. This file helps the server to know crucial details
about the application.
12. What is a war file? Give its importance.
WAR or Web Application Archive file is packaged servlet Web application. Servlet applications
are usually distributed as a WAR files.
WAR file (which stands for "web application archive" ) is a J AR file used to
distribute a collection of J avaServer Pages , servlets , J ava classes , XML files, tag
libraries and static Web pages ( HTML and related files) that together constitute a Web
application.
13. How to specify session time out in Web.XML?
Page 4of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
You can specify session timeout in the <session-timeout> attribute of the <session-config>
element. For example, to specify a session timeout of 30 minutes use:
<session-config>
<session-timeout>30</session-timeout>
</session-config>
14. What is JSP? How is it different from CGI programming?
J SP is a technology for developing Web pages that include dynamic content. A J SP page
contains standard markup language elements, such as HTML tags, just like a regular Web page.
However, a J SP page also contains special J SP elements that allow the server to insert dynamic
content in the page.
CGI is not an efficient solution for developing dynamic Web content. For every request, the Web
server has to create a new operating system process, load an interpreter and a script, execute
the script and then tear it all down again. This is taxing for the server and affects the scalability of
the application.
However, in J SP, each J SP page is compiled into executable code on first request. On
subsequent requests thee executable code is directly invoked instead of recompilation. This
enables a server to handle J SP pages much faster than CGI programs.
15. What are the advantages of JSP?
The advantages of J SP are:
Supports both scripting and element based dynamic content and allows programmers to develop
custom tag libraries to satisfy application specific needs.
Are compiled for efficient server processing.
Can be sent in combination with servlets that handle the business logic of the model supported
by J ava servlet template engines.
It is specification not a product. Different vendors can launch and use different implementations
of J SP, leading to competition for better quality and performance.
It is an integral part of J 2EE, a complete platform for enterprise class applications.
16. What are Servlets? Describe with example.
Servlets are programs that run on a Web server and create Web pages on the fly. To be a
servlet, a class should extend HttpServlet and override doGet or doPost or both methods,
depending on whether data is sent by GET or POST. These methods take two arguments,
HTTPServletRequest and HttpServletResponse. The HTTPServletRequest has methods that let
you find out about incoming information such as FORM data and HTTP request headers. The
HttpServletResponse has method that lets you specify the HTTP response line, response
headers, and obtain a PrintWriter object, used to send output back to the client. For simple
Page 5of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
servlets, most of the effort is spent in println statements that generated the desired page. A
sample servlet is given below:
package hallo;
import java.io.*;
import javax.servlet.*;
import. J avax.servlet.http.*;
public class HelloWorld extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)throws
ServletException, IOexception {
PrintWriter out =response.getWriter();
Out.println("Hello World");
}
}
17. Which two packages implement the servelet API?
The two packages are:
The javax.servlet package contains a number of classes and interfaces that javax.servlet:-
describe and define the contracts between a servlet class and the runtime environment provided
for an instance of such a class by a conforming servlet container.
The javax.servlet.http package contains a number of classes and interfaces javax.servlet.http:-
that describe and define the contr acts between a servlet class running under the HTTP protocol
and the runtime e nvironment provided for an instance of such a class by a conforming servlet co
ntainer.
18. What are the several ways of tracking users?
The several ways in which you can track users are:
Using hidden controls
Using cookie
Using sessions
Using applications
19. What are the disadvantages of hidden controls?
The disadvantages of hidden controls are that they are not secure as any user can access the
HTML source and view their value. Consequently, you cannot store crucial information such as
passwords in them. In addition, they complicate the code many times.
20. What is session?
Page 6of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
Sessions let you preserve data between accesses to a Web page by the same user. Unlike
cookie, sessions are stored on the server itself in files or databases.
21. What is SSL? Why do you require SSL?
SSL or Secure Socket Layer is a protocol that authenticates Web sites to browsers. It is also
used for encrypting communication between browser and Web servers. To enable SSL, you
simply need to install digital certificates or Server ID.
The main role of SSL is to provide security for Web traffic. Security includes confidentiality,
message integrity, and authentication. SSL achieves these elements of security through the use
of cryptography, digital signatures, and certificates.
22. What is XML? Describe in brief.
XML is a simple, common format for representing structured information as text. You can create
your own tags to define and structure data, and transmit it. The basic syntax of XML is extremely
simple. As with HTML, XML represents information as text using tags to add structure. A tag
begins with a name in between angular brackets (<>). In XML, every tag must have a closing tag.
An opening tag, closing tag and any content in between are collectively referred to as an element
of an XML document. Elements can contain other elements but they must be properly nested.
Elements can also contain text or a combination of elements and text.
23. Give an overview about EJBs.
Enterprise J ava Beans (EJ B) is a server-side component that executes specific business logic on
a server when invoked by a local or remote client. EJ B is actually a framework for writing
distributed programs. It involves a standardization agreement that enables a component to run
within any application server. The agreement is accomplished by implementing a set of J ava
interfaces from the EJ B API. Note that EJ Bs are not GUI components.
24. Describe in briefly the entity beans and session beans.
is an object with the following special properties: An entity bean
It is permanent. It does not get destroyed itself after a program finishes executing.
It is network-based. It can be used by any program over a network provided the program is able
to access the bean on the networked machine.
It is executed remotely. Methods of an entity bean run on a server machine. When you call an
entity bean's method, your program's thread stops executing and control passes over to the
server. When the method returns from the server, the thread resumes execution.
It is identified by a primary key. Entity beans must have a primary key. The primary key is unique
- each entity bean is uniquely identified by its primary key. For example, an employee entity bean
may have Social Security number as primary key. You can only use entity beans when your
objects have a unique identifier field or when you add such a field.
Page 7of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
are different from entity beans in that they are not permanent objects. They are Session beans
not shareable in general although it is possible to share them using handles. Session beans can
be used to distribute and isolate processing tasks. Each session bean can be used to perform a
certain task on behalf of its client. The tasks can be distributed on different machines. Session
beans also do not have a primary key. Unlike entity beans, session beans are not primarily meant
to be shared or found later.
25. What is DTD?
DTD or Document Type Definitions is a document that contains grammar rules for validating an
XML document. It is a schema specification method for XML.
26. Discuss the differences between XML and HTML. 4
HTML stands for Hypertext Markup Language. It is a layout and format defining language used to
write Web pages. It allows you to:
Publish documents to the Internet in a platform independent format
Create links to related work from your document
Include graphics and multimedia data in your documents
Link to non-World Wide Web information resources on the Internet
27. What are cascading style sheets? Explain.
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>
Note that the style tag is always placed in the head of the document.
28. What is an application server? 2 Marks
An application server commonly includes a web server so perhaps you can see an application
server as an extension of a web server
29. What is EJB and give the advantages of EJB. 3 Marks
Page 8of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
is a server-side component that executes specific business logic on Enterprise J ava Beans (EJ B)
a server when invoked by a local or remote client. EJ B is actually a framework for writing
distributed programs. It involves a standardization agreement that enables a component to run
within any application server.
Following are the advantages of EJBs:
Many vendor application servers conform to the J 2EE specification allowing you to select a best-
of-breed solution.
To handle fluctuations in resource demand server-side resources can easily be scaled by adding
or removing servers.
Application servers provide access to complex services, such as transaction and security
management, resource pooling, J NDI (J ava Naming and Directory Interface), and component
lifecycle management.
30. What is PERL? 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.
: A Hash is a special kind of an array - an associative array or paired list of elements. Hashes
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;
31. How are JSPs better than Servlets?
Unlike servlets, J SP lets you separate presentation and business logic. You can place the HTML
code (presentation) in J SP along with some dynamic elements. The business logic remains in the
servlets or J avaBeans. This approach helps to overcome the problems with a pure servlet based
approach, such as:
Thorough J ava programming knowledge is needed to develop and maintain all aspects of the
application, since the processing code and the HTML elements are lumped together.
Page 9of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
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 than
be manually embedded into servlet code. This process is time consuming and error prone.
32. What is JSP? Explain JSP elements.
JSP is a technology for developing Web pages that include dynamic content. A JSP page
contains standard markup language elements, such as HTML tags, just like a regular Web page.
However, a JSP page also contains special JSP elements that allow the server to insert dynamic
content in the page.
JSP elements are of 3 types:
Directive Specifies information about the page itself that remains the same between requests. :
For example, it can be used to specify whether session tracking is required or not, buffering
requirements, and the name of the page that should be used to report errors.
Action Performs some action based on information that is required at the exact time the JSP :
page is requested by a browser. An action, for instance, can access parameters sent with the
request to lookup a database.
Scripting Allows you to add small pieces of code in JSP page. These elements are also :
executed when a page is requested.
33. Differentiate between Java & Java scripts. 2 Marks
Java :-
Java Programming language,is an OOP Language and development environment, application
environment, deployment environment. It is standalone programming Language that do not
require a web browser to execute.
Java script:
It is a contained in the HTML source of webpage. It controls document appearance and content.
It also manipulates embedded images and it also interacts with Applets. Its advantage is that it is
simplified,
it doesnt have to be compiled and the source code resides within our HTML document.
34. What are the advantages of using Servlets? 3 Marks
Following are the advantages of using servlets:
It helps to achieve platform independence.
It provides performance improvement as classes stay in the memory once called
Page 10of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
It is much more secure over traditional server sides languages.
For example, no problems of memory leakages and buffer overflows are faced in case of
servlets.
It uses J ava's multithreading capabilities, which gives it a performance gain.
35. What are cookies? And why are cookies used for? 2 Marks
Cookies are small text strings you store on a user's computer. Cookies store information for
tracking users in name-value pairs. When you first visit a website it may store a cookie on your
computer. Next, when you again visit the site it may read or manipulate the value of the cookie
and perform an action based on it. For example, if a site allows you to customize the color of the
user interface, it may set the color selected by you in a cookie on your computer and read the
color value when next time you request the page of the website. The page can them be displayed
in the color stored in the cookie.
36. What is XML? Give the XML document. 3 Marks
XML is a simple, common format for representing structured information as text. You can create
your own tags to define and structure data, and transmit it. The basic syntax of XML is extremely
simple. As with HTML, XML represents information as text using tags to add structure. A tag
begins with a name in between angular brackets (<>). In XML, every tag must have a closing tag.
An opening tag, closing tag and any content in between are collectively referred to as an element
of an XML document. Elements can contain other elements but they must be properly nested.
Elements can also contain text or a combination of elements and text.
Page 11of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
PART B
1. Explain GET and POST method briefly. 5
GET
The Get is one the simplest Http method. Its main job is to ask the server for the resource. If the
resource is available then then it will given back to the user on your browser. That resource may
be a HTML page, a sound file, a picture file (J PEG) etc. We can say that get method is for getting
something from the server. It doesn't mean that you can't send parameters to the server. But the
total amount of characters in a GET is really limited. In get method the data we send get
appended to the URL so whatever you will send will be seen by other user so can say that it is
not even secure.
POST
The Post method is more powerful request. By using Post we can request as well as send some
data to the server. We use post method when we have to send a big chunk of data to the server,
like when we have to send a long enquiry form then we can send it by using the post method.
There are few more rarely used http methods including HEAD, PUT, TRACE, DELETE,
OPTIONS and CONNECT.
2. Discuss the difference between static and dynamic web pages. 5
Static Web pages are not processed by the server and are sent as it is. These pages do not have
any scripting logic and they cannot change according to client's request parameters. Dynamic
Web pages are processed by the server and then the generated content is sent to the client.
They may involve information from a database or some other information such as client's user
name.
In other word we can say that:-
With static web sites, requests for pages are handled by a web server delivering the content of
these HTML files, "as is". They are called static because they don't change very often. With
dynamic web sites there is a difference, requests for pages are a bit more complicated. For each
request, the page (the HTML) is constructed from information stored in files (such as images),
information stored in databases (textual content) and programming logic (both server side such
as PHP, J ava, ASP etc and with "Web 2.0" more client side - J avascript). All really useful sites
(Amazon, Trademe, online banking etc) are dynamic. It would be completely impossible for them
to be anything else, as what they are providing is constantly changing and/or the content is
dependent on what the site visitor actually asked for.
3. Explain in briefly the role played by CGI programming in web programming. 5
Page 12of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
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. 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. PHP is a scripting language designed specifically to make
web programming quick and easy.
The task of a webserver is to respond to requests for webpages issued by clients Purpose:-
(usually web browsers ) by analyzing the content of the request (which is mostly in its URL ),
determining an appropriate document to send in response, and returning it to the client.
If the request identifies a file on disk, the server can just return the file's contents. Alternatively,
the document's content can be composed on the fly. One way of doing this is to let a console
application compute the document's contents, and tell the web server to use that console
application. CGI specifies which information is communicated between the webserver and such a
console application, and how.
The webserver software will invoke the console application as a command. CGI defines how
information about the request (such as the URL ) is passed to the command in the form of
arguments and environment variables . The application is supposed to write the output
document to standard output ; CGI defines how it can pass back extra information about the
output (such as the MIME type , which defines the type of document being returned) by
prepending it with headers .
Some common uses of CGI programming:
Email newsletter subscription manager
Webcalendars and appointment scheduling
Visitor surveys and quizzes
Online tip of the week (with automated archiving)
Page 13of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
Automated online membership database
Discussion boards
Online classified ads
E-commerce
Banner ad management
Automated classified ad system
Online auctions
And many more...
4. Explain any 4 HTML tags with at least 4 attributes with example. 5
The <BODY>tag represents the body of an HTML page and contains the content to be displayed
in the browser window. It has various attributes including:
BACKGROUND: Specifies an image to be displayed in the background of an HTML page. Its
value can be an absolute URL or a relative URL.
BGCOLOR: Sets the color of the background.
TEXT: Sets the default color of normal text for the HTML page.
LINK: Sets the default color of unvisited links in an HTML page.
The <TABLE>tag is used to create tables in HTML pages. It has various attributes such as:
BORDER: Indicates the thickness, in pixels, of the border to be drawn around the table.
CELLPADDING: Determines the amount of space, in pixels, between individual cells in a table.
CEPPSPACING: Determines the amount of space, in pixels, between individual cells in a table.
WIDTH: Determines the width of the table.
The <IMG>tag inserts images in an HTML page. It has various attributes such as:
SRC: Path of the image to be displayed.
ALT: Alternative text to be displayed in case the image cannot be displayed.
LOWSRC: Path of a low resolution version of the image.
HEIGHT and WIDTH: Specifies the dimensions of the image.
The <HR>tag is used to draw a horizontal line in HTML pages. It has various attributes such as:
ALIGN: Specifies the horizontal alignment of the lines that do not span the whole page.
NOSHADE: Reproduces a solid black line that has no shading.
SIZE: Indicates the thickness of the line in pixels.
WIDTH: Defines the horizontal width of the line.
5. Write an HTML program to demonstrate text characteristics tags. 5
The following code demonstrates some of the important text characteristics tags in HTML:
<html>
<head>
<title>Text Characteristics</title>
Page 14of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
</head>
<body>
<p><b><font color ="#0000FF" face ="Arial" size ="5">
Text Characteristics in
</font>
<font color ="#0000FF" face ="Arial" size ="8">
<s>HTML</s>
</b>
</p>
</font>
<i>HTML</i>is a <em>formatting language</em>for Web pages. Below is an example of
<u>HTML code</u><br>
<code>
&lt;HTML&gt;<br>
&lt;HEAD&gt;<br>
&lt;/HEAD&gt;<br>
&lt;/HTML&gt;<br>
</code>
<p><kbd>&</kbd>followed by <kbd>gt</kbd>represents the greater than sign.
</body>
6. Explain ordered list and unordered lists. 5
Ordered lists are numbered list and represented by the <OL>tag in HTML. You can use the tag's
TYPE and START attributes to change the style and sequence of the numbering in the list. The
<LI>tag is used for individual items of the list. Ordered lists are usually used to represent
procedures/sequence of steps in HTML pages. An example of an ordered list is give below:
To copy text in Word:
<OL>
<LI>Select the text.</LI>
<LI>Press Ctrl +C.</LI>
<LI>Click at the location where you want to past the text and pres Ctrl +V.</LI>
</OL>
The unordered list is a bulleted list and represented by the <UL>tag in HTML. You can
use the tag's TYPE attribute to change the style of the bullets in the list. The <LI>tag is used
Page 15of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
for individual items of the list. Unordered lists are usually used to represent various items of a
category or related to a topic. An example of an unordered list is given below:
The various types of domestic animals are:
<UL>
<LI>Dogs</LI>
<LI>Cats</LI>
<LI>Horses</LI>
</UL>
7. Explain briefly about Cascading Style Sheets (CSS). 5
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>
Note that the style tag is always placed in thehead of the document.
8. Write a program to display text in statue bar on click of a button. 5
<html>
<head>
<title>Pop up</title>
</head>
<body onclick ="window.status ='You have clicked!!!'">
<h1>Changing Status Bar Text</h1>
</body>
</html>
9. Explain the methods to access nodes in a document tree. 5
Following are the methods used to access a node in a document tree:
Page 16of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
document.getElementById(): Returns the element or node whose ID is passed as a parameter
to it.
document.getElementsByTagName(): Returns the list of nodes that have the tag passed to the
function as a parameter.
Wecan access a node in three ways:
1. By using the getElementById() method
2. By using the getElementsByTagName() method
3. By navigating the node tree, using the node relationships
1.The getElementById() Method
The getElementById() method returns the element with the specified ID:
Syntax
node.getElementById("id");
The following example gets the element with id="intro":
Example
document.getElementById("intro");
The getElementsByTagName() Method
getElementsByTagName() returns all elements with a specified tag name.
Syntax
node.getElementsByTagName("tagname");
The following example returns a nodeList of all <p>elements in the document:
Example 1
document.getElementsByTagName("p");
10. Explain PEARL control structures with appropriate examples. 5
PERL control structures include:
This construct performs a Boolean test on an expression and 1.If-else and unless condition:
performs actions based on the results of the Boolean test. For example:
If($var==1)
{
$out ="This was one";
}
elseif($var==0)
{
Page 17of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
$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 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.
It is used for iterating over a list of values. The elements of an array can be 2.Foreach loop:
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.
It is also used to perform an action repeatedly as long as a Boolean expression 4.While loop:
evaluates to true as:
$i=0;
while ($i<10)
{
print "$i";
Page 18of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
}
This will print numbers from 0 to 9.
: This performs the reverse action of the while loop. It executes as long as a Boolean 5.Until loop
expression is NOT true. For example:
$i=0;
until ($i>=10)
{
print "$i";
}
This will print numbers from 0 to 9.
11. Write a CGI application which accepts 3 numbers from the user and displays the LCM of
three numbers using GET and POST methods. 6
#!/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 '<form action="ques10.pl" method="post"><pre>';
print 'Enter First Number <input type="text" name="one"><br>';
print 'Enter Second Number <input type="text" name="two"><br>';
print 'Enter Third Number <input type="text" name="three"><br>';
print '<input type="submit" value="Submit"><br>';
print "</pre></form>";
}
print $cgi->end_html;
sub findLCM()
Page 19of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
{
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;
}
12. What is Extra Path Information? Explain with an example.
Besides passing query information to a CGI script, you can also pass additional data known as
extra path information as part of the URL. The server gauges where the CGI program name
ends; anything following that is deemed as extra path information and stored in the PATH_INFO
environment variable. For example the following line calls a script with extra path information:
http://some.machine/cgi0bin/display.pl/cgi_doc.txt
13. Explain how Servlet mapping are done in web.XML. 5
Servlet Mapping is done in Web.xml with the help of the <servlet_mapping>tag as:
<servlet-mapping>
<servlet-name>Controller</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>graph</servlet-name>
<url-pattern>/graph</url-pattern>
</servlet-mapping>
Page 20of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
According to the first mapping, all requests of the form http://localshots:8080/{contextpath}.do will
be mapped to the Controller servlet whereas according to second mapping all request of the form
http://localshots:8080/{contextpath}/graph will be mapped to the graph servlet.
14. Write a JSP program which displays different messages to the user based on the time of
day. 5
<%@ page contentType="text/html;charset=UTF-8" language="java"
import="java.util.Calendar" %>
<html>
<head><title>Time Message</title></head>
<body>
<%
Calendar cal =Calendar.getInstance();
int hh =cal.get( Calendar.HOUR_OF_DAY );
Stringmessage ="";
if( hh <12 )
{
message ="Good Morning!";
}
else if( hh ==12 )
{
message ="Good Noon!";
}
else if( hh >12 && hh <18 )
{
message ="Good Afternoon!";
}
else if( hh >18 && hh <21 )
{
message ="Good Evening!";
}
else
{
message ="Good Night!";
}
%>
<%=message%>
</body>
</html>
15. Explain implicit objects out, request, response in a JSP page. 5
Page 21of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
Following are the implicit objects in a J SP page:
out This implicit object represents a J spWriter that provides a stream back to the requesting :
client. The most common method of this object is out.println(),which prints text that will be
displayed in the client's browser.
request This implicit object represents the javax.servlet.HttpServletRequest interface. The :
request object is associated with every HTTP request. One common use of the request object is
to access request parameters. You can do this by calling the request object's getParameter()
method with the parameter name you are seeking. It will return a string with the values matching
the named parameter.
response This implicit object represents the javax.servlet.HttpServletRequest object. The :
response object is used to pass data back to the requesting client. A common use of this object is
writing HTML output back to the client browser.
16. Explain Servlet life cycle. 5
The lifecycle of a servlet consists of the following main stages:
Instantiation The Web server creates an instance of a servlet. This is based on a request or a :
container startup.
Initialization The Web server creates the instance's init() method. When the Web server loads a :
Web application, it also loads the initialization parameters associated with the application. This
and the previous step occur only once during the lifetime of a servlet.
Service This is the third state in the servlet lifecycle. In this state, the servlet's service() method :
is called, which generates response. The generation of response involves the following steps:
Setting the content type of the response. The receiving application (browser) uses this
information to know how to treat the response data. For example, to generate an HTML output,
the content-type is set to "text html".
The second step is to get PrintWriter object from response. PrintWriter is a class that extends the
java.io writer abstract class. In the case of servlets, the Web server constructs the Print Writer
object from the java.io. OutputStream object associated with the underlying connection from the
client. With TCP/IP based implementations, Web server usually gets OutputStream object from
the socket, uses the object to create the PrintWriter object, and associates with the
HttpServletResponse object. As a result, from within the servlet, you will able to write to object
stream associated with the network association.
Destroy This is the final stage in a servlet lifecycle. In this stage, the destroy() method is called :
before shutting down the servlet.
17. Draw a class diagram to show the relationships between the major classes in the Servlet
API. 5
The class diagram is shown as here:
Page 22of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
18. Describe the request handling cycle and the method invoked on the Servlet by the Servlet
container. 5
Following are the operations done on a servlet by servlet container when a servlet is requested:
1.If servlet instance does not exist in memory, the container:
a.Loads the servlet class and thus creates its instance
b.Calls the init() method on the above class and passes ServletConfig as parameter
2.On any further request service() method of servlet class is called and HttpServletRequest and
HttpServletResponse are passed as parameters to it.
19. Explain in brief how to use hidden controls in a web page? Give an example.5
Using HTML, hidden controls are an easy way to store data in a Web page. You can store data in
a hidden control and then refer to the value of control wherever required. Hidden controls are
often used when you submit a form to itself. That is if your form's ACTION attribute is set to the
same page which contains the form. In this case, every time the page loads you have to
determine whether it is being loaded afresh or after a submission. For this, you can store a text
value such as "DONE" in a hidden control SUBMIT_STATUS, and check for it whenever the page
loads. If request.getParameter(SUBMIT_STATUS) returns a NULL value, it means that the form
is being loaded afresh.
This logic is demonstrated in the following code:
<html>
<head></head>
Page 23of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
<body>
<%
if(request.getParameter("DONE")==null)
{
out.println("You entered your name as:" +getParameter("name"));
}
else
{
%>
<form action ="this.jsp" method ="POST">
Enter your name:<input type ="text" name ="name"></input
<input type ="HIDDEN" name ="DONE" value ="submitted">
<input type ="SUBMIT" value ="SUBMIT">
</form>
<%
}
%>
</body>
</html>
20. List down any 6 methods of javaX.Servlet.Http. Cookie Class and there functionality.
Following are the methods of the Cookie class:
(): Returns the name of the cookie java.lang.String getName
Returns the value of the cookie java.lang.String getValue():
Assigns a new value to a cookie after it has been created void setValue(java.lang.String value):
Sets the path for the cookie by which the browser will send the void setPath(java.lang.String uri):
cookie
Set the maximum age of the cookie in seconds void setMaxAge(int expiry):
Returns the maximum age of the cookie in second int getMaxAge():
21. Explain in brief how to track a user using sessions with an example. 5
You can track user using sessions by storing the details of his/her session with the Web site. For
example, you store the number of times that a user has visited a page and display it to him on
every visit. To track the user using sessions perform the following steps:
Page 24of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
1.Include page directive with the session attribute set to true, at the top of the page, to indicate
that a new session has to be started(if one does not already exist).
2.Check whether a count has already been set before in a session attribute using the
getAttribute() method of the Session class.
3.If the count has not been set, the getAttribute() method will return null. In that case, you can
create a new count value. If a value already exists, you can increment it and store the new value
in the session object.
The above steps are implemented in the following code:
<%
Integer count =(Integer)session.getAttribute("visitcount");
If(count==null)
{
count =new Integer(1);
}
else
{
count =new Integer(visitcount.intValue()+1);
}
session.setAttribute("visitcount", count);
%>
<body>
You have visited this page <%=count%>times.
</body>
22. What are the advantages and disadvantages of EJBs? 5
Following are the advantages of EJ Bs:
Many vendor application servers conform to the J 2EE specification allowing you to select a best-
of-breed solution.
To handle fluctuations in resource demand server-side resources can easily be scaled by adding
or removing servers.
Application servers provide access to complex services, such as transaction and security
management, resource pooling, J NDI (J ava Naming and Directory Interface), and component
lifecycle management.
Following are the disadvantages of EJ Bs:
EJ B has a large and complicated specification.
EJ Bs take time to develop. Also, they are difficult to debug. Occasionally, the bug may not be in
your code but in the application server itself.
Frequently released newer versions of EJ B specifications render application obsolete quickly.
23. Briefly describe the roles of remote and home interfaces in EJBs. 5
Page 25of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
A remote interface is the business end of EJ B. It is the set of services provided by EJ B.
The home interface is the book-keeping interface. It helps clients to create a new instance of an
EJ B, or to find an existing instance of an EJ B. The methods used to find existing EJ Bs are shown
as finder methods. Since session beans are not designed to be shareable, there are no session
bean finder methods.
24. What is a Form? What are the form elements? 5
The HTML form element represents a form in which users can input data and submit it to the
server for processing. The HTML form tag is as follows:
<FORM NAME="name" ACTION ="action.jsp" METHOD ="POST/GET">
The name attribute specified the name for a form. The action attribute specified the URL of the
document or the name of the file to which the form data is submitted for action and the method
attribute specified the HTTP method through which the data is sent to the server.
The action attribute can be a simple static Web page or a servlet. The method can be POST or
GET.
A form includes various other <INPUT>elements such as textbox, list, buttons, or checkboxes.
25. What are CSS? Explain the font properties. 7
Write an HTML program to demonstrate applet embedding. 8
Applets are embedded in HTML pages using the <APPLET>tag. An example of an HTML page
containing an applet which scrolls the specified text across the screen at a specified speed, is
given below:
<HTML>
<HEAD>
<TITLE>Demo Applet</TITLE>
</HEAD>
<BODY>
<APPLET CODE="scrolling_banner.class: CODEBASE =jclasses
WIDTH =240 HEIGHT =400
ALIGN =ABSMIDDLE HSPACE =10 VSPACE =20>
<PARAM NAME = message VALUE ="Use Netscape Navigator to browse the World Wide
Web.">
<PARAM NAME =speed VALUE ="4">
</APPLET>
</BODY>
</HTML>
Page 26of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
26. What is Java script? Explain the uses of Java scripts. 8
J avaScript is a scripting language used to make interactive web pages. It is mostly used as a
client side scripting language. Its uses include:
Control document appearance and content
Control the browser
Interact with document content
Interact with user
Read and write client state with cookies
Interact with applets
Manipulate embedded images
27. What is JSP? What are the advantages of JSP? 8
J SP is a technology for developing Web pages that include dynamic content. A J SP page
contains standard markup language elements, such as HTML tags, just like a regular Web page.
However, a J SP page also contains special J SP elements that allow the server to insert dynamic
content in the page
The advantages of J SP are:
Supports both scripting and element based dynamic content and allows programmers to develop
custom tag libraries to satisfy application specific needs.
Are compiled for efficient server processing.
Can be sent in combination with servlets that handle the business logic of the model supported
by J ava servlet template engines.
It is specification not a product. Different vendors can launch and use different implementations
of J SP, leading to competition for better quality and performance.
It is an integral part of J 2EE, a complete platform for enterprise class applications.
28. Explain the various JSP directives. 7
J SP directives are J SP elements that provide global information about a J SP page. The various
J SP directives are:
page directive Defines information that will globally affect the J SP containing the directive. The :
syntax of a page directive is: <%@ page {attribute ="value"}%>. The various possible attributes
are language, extends, import, session, buffer, autoFlush, isThreadSafe, info, errorPage,
isErrorPage, and contentType.
include directive Used to insert text and/or code at the J SP translation time. Its syntax is: <%@ :
include file ="relativeURLspec" %>. The file attribute can reference a normal HTML file or a J SP
file, whichmust be local to the Web application that contains the directive.
taglib directive States that the including page uses a custom tag library, uniquely identified by a :
URO and associated with a prefix that will distinguish each set of custom tags to be used in the
page. Its syntax is: <%@ taglib uri ="tagLibraryURI" prefix ="tagPrefix"%>.
Page 27of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
29. Explain implicit objects out, request response and session objects in a JSP page. 8
Following are the implicit objects in a JSP page:
out This implicit object represents a JspWriter that provides a stream back to the requesting :
client. The most common method of this object is out.println(),which prints text that will be
displayed in the client's browser.
request This implicit object represents the javax.servlet.HttpServletRequest interface. The :
request object is associated with every HTTP request. One common use of the request object is
to access request parameters. You can do this by calling the request object's getParameter()
method with the parameter name you are seeking. It will return a string with the values matching
the named parameter.
response This implicit object represents the javax.servlet.HttpServletRequest object. The :
response object is used to pass data back to the requesting client. A common use of this object is
writing HTML output back to the client browser.
Session The implicit session object represents the javax.servlet.http.HttpSession object. Its :
used to store objects between client requests, thus providing an almost state full HTTP
interactivity.
30. Explain the main steps in implementing a Servlet. 7
Following are the steps used in implementing a servlet for HTTP communication:
1.Import required servlet packages in the class.
2.Make the class extend HttpServlet.
3.Override methods doGet(), doPost(), or doService() as required by problem in hand.
4.Make an entry for the above servlet in deployment descriptor.
5.Configure any extra options or filters, which are required by the server to function.
31. What is CGI? What are the advantages of CGI? Write a CGI application which accepts the
user information and display the same. 10
#!/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 Nine" );
$text = $cgi->param( 'text' );
if( $text )
{
print "You entered $text";
}
Page 28of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
else
{
print '<form action="ques9.pl" method="get">';
print '<input type="text" name="text"><br>';
print '<input type="submit" value="Submit"><br>';
print "</form>";
}
print $cgi->end_html;
32. Explain the difference between doget() method and dopost() method. 5
doGet() needs to be overridden when the data is submitted to the server using the GET method
whereas the doPost() method needs to be overridden when POST method is used to submit data
to the server.
method is limited with 2k of data to be sent, and doPost() method doesn't have this A doGet()
limitation. A request string for doGet() looks like the following:
http://www.allapplabs.com/svt1?p1=v1&p2=v2&...&pN=vN
method call doesn't need a long text tail after a servlet name in a request. All doPost()
parameters are stored in a request itself, not in a request string, and it's impossible to guess the
data transmitted to a servlet only looking at a request string.
33. What are the differences between sessions and applications? Explain. 8
SessionsSessions are something the server offers us to support user tracking, and theyre
great,
although they can take up a lot of resources on the server. Sessions preserve data between
accesses to a
Web page by the same user.
ApplicationsApplications are much like sessions, as well see, but theyre more general
we can share data between all the JSP pages in a site using applications. In other words, unlike
sessions, applications can be used to track multiple users at the same time
34. Explain the building elements of WEB. 7 Marks
Ans: There are two most important building blocks of web:
Page 29of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
HTML and 2) 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 than 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. 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.
35. Write a CGI application which accepts the user information and display the same. 7 Marks
#!/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 Nine" );
$text = $cgi->param( 'text' );
if( $text )
{
print "You entered $text";
}
else
{
print '<form action="ques9.pl" method="get">';
print '<input type="text" name="text"><br>';
print '<input type="submit" value="Submit"><br>';
print "</form>";
Page 30of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
}
print $cgi->end_html;
36. Describe and compare JSP with CGI programming. 8 Marks
is a technology for developing Web pages that include dynamic content. A JSP page JSP
contains standard markup language elements, such as HTML tags, just like a regular Web page.
However, a JSP page also contains special JSP elements that allow the server to insert dynamic
content in the page.
is not an efficient solution for developing dynamic Web content. For every request, the Web CGI
server has to create a new operating system process, load an interpreter and a script, execute
the script and then tear it all down again. This is taxing for the server and affects the scalability of
the application.
However, in JSP, each JSP page is compiled into executable code on first request. On
subsequent requests thee executable code is directly invoked instead of recompilation. This
enables a server to handle JSP pages much faster than CGI programs.
37. What are hidden controls? List the advantages of hidden controls. 7 Marks
Ans: Using HTML hidden control is an easy way to store data in a webpage. The user set the
text to store in a hidden control in a text field. The code stores the text, the user type in the
hidden control.
Advantages: A hidden control in a Web page is the easiest way of associating some information
with the user thats not directly accessible to him. Hidden controls to store data in the Web page
sent to the browser and then sent back to the server
38.Summarize salient features of HTTP protocol. 10 Marks
that is defined in several RFCs located at the Internic. HTTP is arequest- HTTP is a protocol
response type protocol that specifies that a client will open a connection
to a server then send a request using a very specific format. HTTP is a
language spoken between our web browser (client s/w) and a web server
(server software) so that they can communicate with each other and
exchange files. Client/server system is a very keen way of distributing
information across information systems like a local area network (LAN), a
wide area network (WAN), or the Internet. A client/server system works
Page 31of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
something like this: A big hunk 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. The server software will then accesses the server
hardware, find the requested file, send it back over the wires to the client who requested it, and
then wait for another request from the same or another client. The client software however, deals
with all the underlying client/server protocol stuff and then displays the document. Web
programming is a game of getting user input, processing that input, and returning a dynamic
response.
39. With syntax explain the five TYPE attribute that the INPUT tag defines. 10 Marks
The INPUT tag defines a form element that can receive user input. The TYPE attribute
determines the specific sort of form element to be created. TYPE can be one of the following:
INPUT TYPE=BUTTON A button appears in the form. We must specify JavaScript :
code as the value of the ONCLICK attribute to determine what happens when the user clicks the
button.
Syntax :< INPUT TYPE="BUTTON" -NAME="buttonName" -VALUE=" buttonText" ONCLICK="
JScode">
: A checkbox is a toggle that the user can INPUT TYPE=CHECKBOX
select (switch on) or deselect (switch off.) Syntax : <INPUT TYPE=CHECKBOX
-CHECKED NAME=name -ONCLICK=JScode -VALUE=checkboxValue>
: This places an element on an HTML form that lets the user INPUT TYPE=FILE
supply a file as input. When the form is submitted, the content of the specified file is sent to
the server as the value portion of the name/value pair for this input element. Syntax :< INPUT
TYPE="FILE" -NAME=" name" -VALUE=" filename" >
: A hidden input element is an invisible element whose main INPUT TYPE=HIDDEN
purpose is to contain data that the user does not enter. This data gets sent to the invoked CGI
program when the form is submitted. Syntax : <INPUT TYPE="HIDDEN" -NAME=" name"
VALUE=" value" >
: When a user clicks a submit button, the form is submitted, INPUT TYPE=SUBMIT
which means that the ACTION specified for the form is invoked. Syntax: <INPUT TYPE
Page 32of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
="SUBMIT" -NAME=" name" -VALUE=" value" >
: A password element is a text input field in which each INPUT TYPE=PASSWORD
character typed is displayed as a character such as * or a black dot to conceal the actual value.
Syntax: <INPUT TYPE="PASSWORD" -MAXLENGTH="maxChar -NAME
="name" -ONSELECT="JScode "-SIZE="charLength" -VALUE="textValue >
40. Explain in brief ordered list tags.
The OL tag displays an ordered, or numbered, list. The default numbering style is determined by
the browser, but we can use the tags TYPE attributes to change the numbering sequence and
numbering style. Use the LI tag to designate the individual list items.
Syntax : <OL -START="value"
TYPE= "A"|"a"|"I"|"i"|"1" -CLASS= "styleClass -ID="namedPlaceOrStyle"
LANG=ISO -STYLE=style > </OL> Example: The following example
uses the LI tag to define three list elements in an ordered list. The numbers are
shown as roman numerals and the first item has the number three.
<P>The following steps outline how to create HTML files :</P> <OL START="3" TYPE="I">
<LI> Use a text editor or Netscape Composer to create our HTML file.<LI> Put the HTML files
on a web server.<LI> Test the files by viewing them in a web browser.</OL>
41. Explain the methods to access nodes in a document tree. 10mks
methods for accessing and creating other nodes in the document tree. Some methods are:
getElementById(), getElementsByTagName(), createElement(), createAttribute(),
createTextNode().
All of the above methods (except getElementsByTagName()) can only be used against the
document
object, i.e., using the syntax : document.methodName().
42. Explain document object model. 5 Marks
The Document Object Model or DOM is the interface that allows you to programmatically access
and manipulate content of a web page. It provides a structured, object-oriented, representation of
Page 33of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
the individual elements and content in a page with methods for retrieving and setting the
properties of those objects. It also provides methods for adding and removing such objects,
allowing you to create dynamic content.
The DOM also provides an interface for dealing with events, allowing you to capture and respond
to user and browser actions.
43. What is a web server? Explain. 5 Marks
The Web server is the software responsible for accepting browsers' requests, retrieving the
specified file or executing the script, and returning its content to the browser. Popular Web
servers include Tomcat, Apache, and IIS.
A Web server is a software program which serves web pages to web users (browsers).
A web server delivers requested web pages to users who enter the URL in a web browser. Every
computer on the Internet that contains a web site must have a web server program.
The computer in which a web server program runs is also usually called a web server. So, the
term web server is used to represent both the server program and the computer in which the
server program runs.
Characteristics of web servers
A web server computer is just like any other computer. The basic characteristics of web servers
are:
- It is always connected to the internet so that clients can access the web pages hosted by the
web server.
- It has an application called web server running always.
In short, a web server is a computer which is connected to the internet/intranet and has a
software called web server. The web server program will be always running in the computer.
When any user try to access a website hosted by the web server, it is actually the web server
program which delivers the web page which client asks for.
All web sites in the internet are hosted in some web servers sitting in different parts of the world.
44. Explain the two approaches that a web application can be deployed in Tomcat. 10 Marks
How do you create a Cookie? Explain with an example. 9 Marks
Ans.
You can create a cookie by instantiating an object of the Cookie class. For example, to create a
cookie name 'mycookie', with the value 'this is the cookie value', you can use the following code
snippet:
Cookie mycookie = new Cookie("mycookie", "this is the cookie value");
Page 34of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
mycookie.setMaxAge(24*60*60);
respone.addCookie(mycookie)//install cookie on browser
The setMaxAge() method sets the time after which the cookie will expire. The
response.addCooki() method will install the cookie on the browser.
45. With the help of an example explain the embedding of an image in an HTML tag. 7
<html>
<head>
<title>Image embedding</title>
<h1>This is my First page of image embedding</h1>
</head>
<body>
<img src=abc.gif>
</body>
</html>
46. List the differences between web server and application server. 7
The main differences between Web servers and application servers are:
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.
47. With the help of an example explain JSP elements. 8
JSP elements are of 3 types:
Directive: Specifies information about the page itself that remains the same between requests.
For example, it can be used to specify whether session tracking is required or not, buffering
requirements, and the name of the page that should be used to report errors.
<%@ page/include/taglib %>
Action: Performs some action based on information that is required at the exact time the JSP
page is requested by a browser. An action, for instance, can access parameters sent with the
request to lookup a database. Scripting: Allows you to add small pieces of code in JSP page.
These elements are also executed when a page is requested.
Page 35of 35 52.WebProgramming
www.rkm.vrmsil.com Solvedby:- Nishant &RKM
Some Additional Questions Please solve yourself.
What is meant by WWW? Explain its significances.
What do you mean by Web Page and Web Site? Explain with an example.
What are a Web Server and Web Browser? Give two examples to each.
Explain the two main ways that HTTP protocol to send information to a web server.
Explain the tags that use to design tables.
Explain how to track users using SESSIONS, APPLICATIONS and JAVA BEANS.
What do you mean by protocol? Give the name of those protocols which help in web and
explain working of those protocols.
Write a Java script program to display a digital clock. And also explain the execution of Java
script..
Outline the main steps in implementing a Servlet.
What are the steps followed to configure the server Apache.
Explain CGI - Pm module with an example.
What is a war file? Explain its importance.
With the help of an example explain any five CGI environment variables.
Write a CGI application which accepts three numbers from the used and display biggest
number
What are sessions? Explain in brief how to track a user using sessions with an example.
Explain any four CGI environment variables.
Describe the request handling cycle, and the methods invoked on the Servlet by the Servlet
container.
What is SSL? Why do you require SSL?
Write a Java Servlet program using HTML to show all the parameter names that were sent and
puts them in table.
Explain JSP error handling.
In brief explain two types of PEARL variables.
How to create a menu using Java Script.
Write a HTML program to insert a selection list in a form.

You might also like