Você está na página 1de 26

1. What is web?

Ans. A Web is a complex network of international, cross platform, and cross cultural
communicating devices, connected to each other without any ordering or pattern.


2. Explain GET and POST methods.

Ans. : 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
(JPEG) etc. We can say that get method is for getting something from the server. It
doesnt mean that you cant 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.


3. What is Javascript?

Ans. JavaScript is a scripting language (like a simple programming language).
JavaScript 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.

JavaScript does not have any graphics capabilities, except for the ability to format
and display HTML. For security reasons, client-side JavaScript does not allow the
reading or writing of files. Obviously, you wouldnt want to allow an untrusted
program from any random web site to run on your computer and rearrange your
files.

4. Write an HTML program for applet embedding.

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

5. Write a syntax to create hyper link.

Ans. <a href=www.google.com>Google Link</a>

6. What are text nodes?

Ans. A text node represents every continuous string of character data in the
body of an HTML page .Text nodes represent content, or character data. They
will have a parent node and possibly sibling nodes, but they cannot have child
nodes.

For example, in<p id-node2>"This is the <b>initial</b>text.</p>, there are text
nodes "This is the", "initial", and "text".Chapter Four

7. What is query string? Explain with example.

Ans. http://my.system/cgi-bin/name.pl?fortune
Up to the question mark(?),the URL should look familiar. It is merely a CGI script
being called, by the name name.pl. Whats new here is the part after the ?. The
information after the ? character is known as a query string. When the server is
passed a URL with a query string, it calls the CGI program identified in the first part
of the URL (before the ?) and then stores the part after the ? in the environment
variable QUERY_STRING. The following is a CGI program called name.pl that uses
QUERY_STRING to print the information passed.
#!/usr/local/bin/perl
print Content-type: text/plain, \n\n;
$query_string = $ENV{QUERY_STRING};
if ($query_string eq fortune) {
print query string is fortune;
} elsif ($query_string eq finger) {
print query string is finger;
} else {
print invalid query string;
}
exit (0);
You can execute this script as either:
http://some.machine/cgi-bin/name.pl?fortune
http://some.machine/cgi-bin/name.pl?finger
or
http://some.machine/cgi-bin/name.pl
and you will get different output.

8. What is extra path information?

Ans. 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. "HTML is the language of web" Explain.

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

10. Brief about role played by CGI programming in web programming.

Ans. CGI stands for Common Gateway Interface. CGI is the part of the Web
server that can communicate with other programs running on the server. CGI
provides a gateway between a human user with unexpected and complex
needs, and a powerful, command/logic oriented server. All CGI applications must
translate the needs of clients into server requests, and translate server replies
into meaningful well-presented answers. The CGI script will be responsible for
processing the form data, which is filled by user and responding to the client in
the form of dynamically generated HTML. With CGI, the Web server can call up a
program, while passing user-specific data to the program (such as what host the
user is connecting from, or input the user has supplied using HTML form syntax).
The program then processes that data and the server passes the programs
response back to the Web browser.

11. What is HTML? Explain any four html tags with at least four attributes with
examples.

Ans.
HTML stands for Hypertext Markup Language. It is a layout and format defining
language used to write Web pages. It allows you to:

1. Publish documents to the Internet in a platform independent format
2. Create links to related work from your document
3. Include graphics and multimedia data in your documents
4. Link to non-World Wide Web information resources on the Internet

1) HTML (outermost tag) -The HTML tag identifies a document as an HTML
document. All HTML documents should start with the <HTML> tag and end with
the </HTML> tag.

2) HEAD - (document header)-The HEAD tag defines an HTML document
header. The header contains information about the document rather than
information to be displayed in the document. The web browser displays none of
the information in the header, except for text contained by the TITLE tag.- We
need to put all header information between the <HEAD> and </HEAD> tags,
which should precede the BODY tag.-The HEAD tag can contain TITLE, BASE,
ISINDEX, META, SCRIPT, STYLE, and LINK tags.-Syntax :<HEAD>...</HEAD>

3) Title:-The HTML title tag is used for declaring the title of the HTML document.-
The title is usually displayed in the browser's title bar (at the top). -The title tag is
placed between the <head> and </head> tags.

4) Body-The BODY tag specifies the main content of a document. You should
put all content that is to appear in the web page between the <BODY> and
</BODY> tags.-The BODY tag has attributes that help us to specify
characteristics for the document.-also we can specify the background color or an
image to use as a tiled background for the window in which the document is
displayed.
For example:-

<html>
<body>
<div id="container">
<div id="contents">
<table>
<tbody>
<tr>
<td class="author">####I want whatever is located here ###</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>

12. Explain ordered lists and unordered lists.

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

13. Explain briefly about cascading style sheets.

Ans.
CSS stands for Cascading style sheets. CSS is the part of DHTML that controls
the look and placement of the elements on a page. With CSS we can basically
set any style property of any element on a HTML page. One of the biggest
advantages with CSS instead of the regular way of changing the look of elements
is that we split content from design. If we want to change like the font size of our
main text we just change it in the CSS file and all pages are updated. In CSS
program always place the style tag inside the head of document.
The syntax for CSS code is: <style type=text/css>
Element{property1:value;property:value2} </style>
Let us see couple of examples:
We always place the style tag inside the head of the document. So a document
could look like this.
All H5 heading on that page would then look like this:
<html><head>
<style type="text/css">
H5{background-color:blue; color:white; font-size:20px}
</style><body><h5>Cascading style sheets</h5>
</body></html>

14. What is DOM? What are the differences between HTML and DHTML.

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

Dynamic HTML. -An extension of HTML that enables, among other things, the
inclusion of small animations and dynamic menus in Web pages.-DHML used
events, methods, properties to insulate dynamism in HTML Pages.- DHTML code
makes use of style sheets and JavaScript.- file saved as the .dhtml format
instead of .htm or .html. [p] HTML - Hyper Text Markup Language. -A
predominant markup language for web pages. It provides a means to describe
the structure of text-based information in a document by denoting certain text
as links, headings, paragraphs, lists, and so on. - file is save with extension .htm
or .html. -HTML is written in the form of tags, surrounded by angle brackets.

15. What is CGI? Give applications of CGI and explain briefly.

Ans.
CGI or Common Gateway Interface is a specification which allows web users to
run programs from their computer. CGI is the part of the Web server that can
communicate with other programs running on the server. The Web server can
call up a program, while passing user-specific data to the program. The program
then processes that data and the server passes the programs response back to
the Web browser. Some of the possible applications of CGI are:

1) Forms: - One of the most prominent uses of CGI is in processing forms are
subsets of HTML that allow the user to supply information forms. The forms
interface makes Web browsing an interactive process for the user and the
provider.

2) Gateways: - CGI provides a solution to the problem in the form of a gateway.
We can use a language such as or a perl or a DBI extension to Perl to form SQL
queries to read the information contained within the database. Once we have the
information, we can format and send it to the client. In this case, the CGI program
servers as a gateway to the Oracle database.

3) Virtual Documents: - Virtual, or dynamic, document creation is at the heart of
CGI. They are created on the fly in response to a users information request. We
can create virtual HTML, plain text, image, and even audio documents.b) In brief
explain two types of PEARL variables.

16. Explain different types of PEARL variables.

Ans.
Perl has three types of variables: scalars, arrays, and hashes.

Scalars:- A scalar variable stores a single (scalar) value. Perl scalar names are
prefixed with a dollar sign ($),
so for example, $x, $y, $z, $username, and $url are all examples of scalar
variable names. Heres how
variables are set:
$foo = 1;
$name = Fred;
$pi = 3.141592;
In this example $foo, $name, and $pi are scalars. You do not have to declare a
variable before using it,
but its considered good programming style to do so. There are several different
ways to declare variables,
but the most common way is with the my function:
my $foo = 1;
my ($name) = Fred;
my ($pi) = 3.141592;
my simultaneously declares the variables and limits their scope (the area of code
that can see these variables) to the enclosing code block. You can declare a
variable without giving it a value:
my $foo;
You can also declare several variables with the same my statement:
my ($foo, $bar, $blee);

Array:- An array stores an ordered list of values. While a scalar variable can only
store one value, an array can store many. Perl array names are prefixed with an
@-sign. Here is an example:
my @colors = (red,green,blue);
Each individual item (or element) of an array may be referred to by its index
number. Array indices
start with 0, so to access the first element of the array @colors, you use
$colors[0]. Notice that when
youre referring to a single element of an array, you prefix the name with $
instead of @. The $-sign again
indicates that its a single (scalar) value; the @-sign means youre talking about
the entire array.
If you want to loop through an array, printing out all of the values, you could print
each element one at
a time:
my @colors = (red,green,blue);
print $colors[0]\n; # prints red
print $colors[1]\n; # prints green
print $colors[2]\n; # prints blue
A much easier way to do this is to use a foreach loop:
my @colors = (red,green,blue);
foreach my $i (@colors) {
print $i\n;}

Hashes :--A hash is a special kind of array an associative array, or paired list
of elements. Each pair consistsof a string key and a data value.

Perl hash names are prefixed with a percent sign (%). Heres how theyre
defined:
my %colors = ( red, #ff0000,
green, #00ff00,
blue, #0000ff,
black, #000000,
white, #ffffff );

This particular example creates a hash named %colors which stores the RGB
HEX values for the
named colors. The color names are the hash keys; the hex codes are the hash
values.

Remember that theres more than one way to do things in Perl, and heres the
other way to define thesame hash:

my %colors = ( red => #ff0000,
green => #00ff00,
blue => #0000ff,
black => #000000,
white => #ffffff );

The => operator automatically quotes the left side of the argument, so enclosing
quotes around the key names are not needed.

17. What is Web server? List out differences between web server and
application server.

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

Web server: Web server is the software responsible for accepting browser
requests, retrieving its content & returning its content. By default, Web browsers
use port 80 for their requests. Web servers are often called httpd, using a UNIX
convention in which daemons are named with the name of the service followed
by the letter d. Web servers first retrieve the request using Berkeley sockets.
Most web servers on Internet today run on UNIX machines.

Application server: An application server commonly includes a web server so
perhaps we can see an application server as an extension of a web server. In
application server you can deploy a java components ranging from simple java
application to server side business components. Usually when we want to deploy
EJBs we will go for App servers like web-logic or web-sphere. In application
server, ejb-jar.xml or application.xml file is used as deployment descriptor.

18. What is JSP? Explain different JSP directives.

Ans.

JSP stands for Java Server Pages. It is a technology for developing web pages
that include dynamic content. A JSP page can change its content based on any
number of variable items, including the identity of the user, the users browser
type, information provided by the user, and selections made by the user.

JSP directives are JSP elements that provide global information about a JSP
page. The various JSP directives are:

page directive: Defines information that will globally affect the JSP 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 JSP translation time. Its
syntax is: <%@ include file = "relativeURLspec" %>. The file attribute can
reference a normal HTML file or a JSP file, which must 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"%>.

19. Explain implicit objects in JSP page.

Ans.

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.

pageContext:- The pageContext object provides access to the namespaces
associated with a JSP page. It also provides accessors to several other JSP
implicit objects. A common use for the pageContext is setting and retrieving
objects using the setAttribute() and getAttribute() methods.

Page:- The page object contains a reference to the current instance of the JSP
being accessed. The page object is used just like this object, to reference the
current instance of the generated servlet representing this JSP.


20. How do you track different users in servlets? Illustrate with an example.

Ans.


21. What is XML? Explain with tags.

Ans.

Extensible markup language is a text-based markup language that enables
to store data in a structured format by using meaningful tags. XML is a
cross-platform, h/w & s/w independent markup language. XML allows
computers to store data in a format that can be interpreted by any other
computer system. XML can be used to transfer structured data between
various systems. Xml is used as a common data interchanges format in a
number of applications. XML is extremely simple. XML represents
information as text using tags to add structure. A tag begins with a name
sandwiched between less-than (<) and greater-than (>) characters.

Advantages of XML:
a) it provides a way of creating domain-specific vocabulary.
b) It enables smart searches.
c) It provides user-selected view of data. d) it allows granular updates.

XMl Document- <?xml version=1.0" encoding=UTF-
8"?><MyDocument></MyDocument>
e.g.:<?xmlversion=1.0?>
<authors><author><firstname>raj</firstname><lastname><kumar</lastnam
e></author></authers>



22. Explain session beans and entity beans.

Ans.
An entity bean is an object with the following special properties:

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.

Session beans are different from entity beans in that they are not permanent
objects. They are 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.

23. Write a short note on:

i) Static Vs Dynamic web pages.
The majority of the web pages on the Internet today are static HTML pages.
HTML pages are simple text files that are displayed by your browser upon
request. Static pages are easily read by search engine spiders.

Dynamic Web pages, on the other hand, contain little actual text. They are
created each time they are requested, retrieving information from a database.
The information retrieved depends upon the input query.

Cookie data, query strings, session id, or specific values are examples of the
types of information required for a dynamic page to be created. Spiders are not
capable of providing this type of information and therefore unable to provide
appropriate information they simply stop indexing dynamic sites. Dynamic pages
produce HTML code, and send that code to your browser.

Visitors find dynamically generated web pages to be useful because they are
provided instant access to highly relevant information. Dynamic sites are also
easy to update. New products can be added by simply editing the database. This
saves countless hours (and dollars) to update multiple static pages. Dynamic web
pages are created using technologies like CGI, JSP/ASP, Cold Fusion etc.

URLs of dynamically generated pages often contain question marks (?),
percentage signs (%) and other symbols (&, + and $) or text (cgi-bin) making up
the query string. Most spiders (Used in search engines) can not read to the right
of the question mark (?) and therefore these pages are not indexed.

ii) Cookies.
This is probably the most common way of tracking users on the Internet. You can
store information in a users computer using cookies, and retrieve it when you
need it. You can also specify how long the cookie should exist before being
deleted by the browser.

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

24. What is the difference between intranet and internet ?
Ans. Internet and Intranet are both networks. However, the Internet is a network of
networks, involving all communicating devices over the Web. However, an Intranet is
limited to the users, machines, and software programs of a specific organization.

25. Write an HTML program for inserting image.
Ans.
<html>
<head>
<title>How To Insert An Image</title>
</head>
<body>
<img src="URL of image" alt="Just in case" title="Tooltip" height="25px"
width="50px" />
</body>
</html>


26. List the rules for constructing XML tags.
Ans.
XML elements must follow these naming rules:
Names can contain letters, numbers, and other characters
Names cannot start with a number or punctuation character
Names cannot start with the letters xml (or XML, or Xml, etc)
Names cannot contain spaces.

27. What is HTML? discuss different header tags with example..
Ans.
HTML stands for Hypertext Markup Language. It is a layout and format defining
language used to write Web pages. It allows you to:
Heading Tags
TITLE
The <title> tag defines the title of the document.
Example:-
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
The content of the document......
</body>
</html>

BASE
The <base> tag specifies the base URL/target for all relative URLs in a page
Example:-
<head>
<base href="http://www.w3schools.com/images/" target="_blank">
</head>


META
The <meta> tag provides metadata about the HTML document. Metadata will not be
displayed on the page, but will be machine parsable.
Example:--
Define keywords for search engines:
<meta name="keywords" content="HTML, CSS, XML, XHTML, JavaScript">
Define a description of your web page:
<meta name="description" content="Free Web tutorials on HTML and CSS">

STYLE
The <style> tag is used to define style information for an HTML document.
Inside the <style> element you specify how HTML elements should render in a
browser:

Example:--
<head>
<style type="text/css">
body {background-color:yellow;}
p {color:blue;}
</style>
</head>

LINK
The <link> tag defines the relationship between a document and an external resource.
The <link> tag is most used to link to style sheets:
Example:---
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>

28. Write a note on HTML tables.
Ans.
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 use the TD tag to define table
cells.

The TABLE tag can also contain a CAPTION tag, which specifies the caption for the table.

You can specify the width of the border surrounding the table and the default background
color of the table. (Individual rows and cells in the table can have their own background
color.) You can use the CELLSPACING attribute to specify the distance between cells in the
table and the CELLPADDING attribute to specify the distance between the border and
content of every cell. If you specify the width and height of the table, the browser will do its
best to make the table fit the specified dimensions, but in some cases this may not be
possible. For example, if the table contains cells that contain non-wrapping long lines, the
table may not fit in a specified width.

Syntax
<TABLE
ALIGN="LEFT|RIGHT"
BGCOLOR="color"
BORDER="value"
CELLPADDING="value"
CELLSPACING="value"
HEIGHT="height"
WIDTH="width"
COLS="numOfCols"
HSPACE="horizMargin"
VSPACE="vertMargin"
>
...
</TABLE>

ALI GN
specifies the horizontal placement of the table.

BGCOLOR=color
sets the color of the background for the table. This color can be overridden by a BGCOLOR
tag in the TH, TR, or TD tags. See Color Units for information about color values.

BORDER=value
indicates the thickness, in pixels, of the border to draw around the table.

CELLPADDING=value
determines the amount of space, in pixels, between the border of a cell and the contents of the
cell. The default is 1.


CELLSPACING=value
determines the amount of space, in pixels, between individual cells in a table. The default is 2.

HEIGHT=height
specifies the height of the table.

WIDTH=width
defines the width of the table.

COLS=numOfCols
indicates how many virtual columns of equal width fit in the width of the window.

HSPACE=horizMargin
specifies the distance between the left and right edges of the table and any surrounding content.

VSPACE=vertMargin
specifies the distance between the top and bottom edges of the table and any surrounding
content.

Example
The following example creates a three-column, four-row table, with a yellow background. The
caption Tables are as easy as one, two, three is displayed at the bottom of the table.

<TABLE BORDER CELLPADDING="8" CELLSPACING="4" BGCOLOR=yellow>
<TR><TH> English </TH><TH> Spanish </TH><TH> German </TH></TR>
<TR><TD> one </TD><TD> uno </TD><TD> ein </TD></TR>
<TR><TD> two </TD><TD> dos </TD><TD> zwei </TD></TR>
<TR><TD> three </TD><TD> tres </TD><TD> drei </TD></TR>
<CAPTION ALIGN="BOTTOM"> <B>Table 1</B>: Tables are as easy as one,
two, three
</CAPTION>
</TABLE>

29. What are CGI environment variables ? Explain.
Ans.
When a CGI program is called, the information that is made available to it can be roughly
broken into three groups :-
Information about the client, server, and user
From data that the user supplied
Additional pathname information
Most information about the client, server, or user is placed in CGI
environment variables. The environment variables are :-
1. GATEWAY_INTERFACE: - it defines the revision of the CGI that the server uses.
2. SERVER_NAME: -it defines the servers hostname or IP address.
3. REQUEST_METHOD: - it defines the method with which the information request was
issued.
4. PATH_INFO: - it defines extra path information passed to a CGI program.
5. SCRIPT_NAME: - it defines the virtual path of the script being executed.

30. How to deploy web applications in Tomcat web server ? Discuss.
Ans.
Tomcat will operate under any Java Development Kit (JDK) environment that provides a JDK
1.2 (also known as Java2 Standard Edition, or J2SE) or later platform. You will need a Java
Development Kit, as opposed to a Java Runtime Environment, so that your servlets, other classes,
and JSP pages can be compiled. Tomcat 5 has been extensively tested with JDK 1.3.1, which is
recommended. Binary downloads of the Tomcat server are available from
(http://jakarta.apache.org/binindex.cgi).

Before describing how to organize your source code directories, it is useful to examine the
runtime organization of a web application. Prior to the Servlet API Specification, version 2.2,
there was little consistency between server platforms. However, servers that conform to the 2.2
(or later) specification are required to accept a Web Application Archive in a standard format,
which is discussed further below.

A web application is defined as a hierarchy of directories and files in a standard layout. Such a
hierarchy can be accessed in its unpacked form, where each directory and file exists in the
filesystem

separately, or in a packed form known as a Web ARchive, or WAR file. The former format is
more
useful during development, while the latter is used when you distribute your application to be
installed.

The top-level directory of your web application hierarchy is also the document root of your
application. Here, you will place the HTML files and JSP pages that comprise your applications
user interface. When the system administrator deploys your application into a particular server, he
or she assigns a context path to your application (a later section of this manual describes
deployment on Tomcat). Thus, if the system administrator assigns your application to the context
path /catalog, then a request URI referring to /catalog/index.html will retrieve the index.html file
from your document root.

To facilitate creation of a Web Application Archive file in the required format, it is convenient to
arrange the executable files of your web application (that is, the files that Tomcat actually uses
when executing your app) in the same organization as required by the WAR format itself. To do
this, you will end up with the following contents in your applications document root directory:

*.html, *.jsp, etc. - The HTML and JSP pages, along with other files that must be visible to the
client browser (such as JavaScript, stylesheet files, and images) for your application. In larger
applications you may choose to divide these files into a subdirectory hierarchy, but for smaller
apps, it is generally much simpler to maintain only a single directory for these files.

/WEB-INF/web.xml - The Web Application Deployment Descriptor for your application. This is
an XML file describing the servlets and other components that make up your application, along
with any initialization parameters and container-managed security constraints that you want the
server to enforce for you. This file is discussed in more detail in the following subsection.

/WEB-INF/classes/ - This directory contains any Java class files (and associated resources)
required for your application, including both servlet and non-servlet classes, that are not
combined into JAR files. If your classes are organized into Java packages, you must reflect this in
the directory hierarchy under / WEB-INF/classes/. For example, a Java class named
com.mycompany.mypackage.MyServlet would need to be stored in a file named /WEB-
INF/classes/com/mycompany/mypackage/MyServlet.class.

/WEB-INF/lib/ - This directory contains JAR files that contain Java class files (and associated
resources) required for your application, such as third party class libraries or JDBC drivers.
When you install an application into Tomcat (or any other 2.2/2.3-compatible server), the classes
in the WEB-INF/classes/ directory, as well as all classes in JAR files found in the WEB-INF/lib/
directory, are made visible to other classes within your particular web application. Thus, if you
include all of the required library classes in one of these places (be sure to check licenses for
redistribution rights for any third party libraries you utilize), you will simplify the installation of
your web application no adjustment to the system class path (or installation of global library
files in your server) will be necessary.

31. Briefly describe basic mechanism of web server.
Ans.
A Web server first retrieves a client request using Berkley sockets, which is a
mechanism used for communicating over a network. The Web server listens for
request on a particular port on the server machine. For HTTP request, this port is by
default set to 80. When the server receives the request, it locates the document being
requested. It looks for the file under the document root directory. For example, if the
document root is /usr/local/httpd/htdocs and the client requests the document
/staff/matthew.html, then the server retrieves
/usr/local/httpd/htdocs/staff/matthew.html. If the URL does not specify a file but just
a directory, the server returns the directory index file, generally called index.html or
welcome.html.
The server sends the contents of the file back to the client, along with some HTTP
response headers.

32. Write a simple servlet program that generates HTML output.
Ans.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
PrintWriter out = response.getWriter();

out.println("<html>");
out.println("<body>");
out.println("<h1>Servlet test</h1>");

out.println("Hello, there!");

out.println("</body>");
out.println("</html>");
}
}

HTML OUTPUT: Servlet test
Hello, there!

33. What are cookies ? Explain in brief.
Ans.
Cookies are the small text files that are used by a web server to keep track of users.
they are created by the server and sent to the client within the HTTP response headers.
the client saves the cookies in the local hard disk and sends them along with the
HTTP requests headers to the server. cookies can be used by the server to find out the
computer name, IP address or any other details of the client computers.[p] Cookies
have been of concern for Internet privacy, since they can be used for tracking
browsing behavior. ssession cookie -Also called a transient cookie, a cookie that is
erased when the user closes the Web browser. The session cookie is stored in
temporary memory and is not retained after the browser is closed. Session cookies do
not collect information from the users computer. They typically will store
information in the form of a session identification that does not personally identify the
user. persistent cookie -Also called a permanent cookie, or a stored cookie, a cookie
that is stored on a users hard drive until it expires (persistent cookies are set with
expiration dates) or until the user deletes the cookie. Persistent cookies are used to
collect identifying information about the user, such as Web surfing behavior or user
preferences for a specific Web site.





34. List down different classifications of HTML tags and give examples.
Ans.
Tags can be classified as:
Tags for document structure: HTML and HEAD
Heading tags: TITLE and LINK
Block-level text elements: H1 through H6, P
Lists: OL and UL
Text characteristics: B, I , FONT

35. Explain servlet life cycle.
Ans.
The lifecycle of a Servlet consists of the following fundamental stages:
Instantiation - The web server creates an instance of a servlet. This based
on a request or a container startup
Initialization - The web server creates the instances init() method. When web
server loads a web application, it also loads the initialization parameters
associated with the application.
The above two states occur only once during the lifetime of a servlet instance.
Service - This is the third state in the servlet lifecycle. In this state the servlets
service() method is called which generates response. The generation of
response involves the following
steps:
1. 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.
2. The second step is to get PrinterWriter object from reponse. PrintWriter is a
class from java.io package that extends the java.io.writer abstract class. In the
case of servlets the web server constructs the PrinterWriter object from the
java.io.OutputStream object associated with the underlying connection from
the client.
Destroy - This is the final stage in a servlet lifecycle. In this tagethe destroy()
method is calledbefore shutting down the Servlet.


36. Explain the usage of script tags.
Ans.
The SCRIPT tag specifies client-side JavaScript code, which means
JavaScript code that runs directly
in the browser. The browser treats everything between the <SCRIPT> and
</SCRIPT> tags as script elements. For example, the browser interprets text
within angle brackets as a script element, not as an
HTML element.You can include <SCRIPT> tags anywhere in your HTML
Syntax
<SCRIPT
LANGUAGE="languageName"
SRC="location"
>
...
</SCRIPT>.
For Example:-
<HTML>
<HEAD><TITLE>Script Example</TITLE>
</HEAD>
<SCRIPT language="JavaScript">
function changeBGColor (newcolor) {
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>
</ BODY>
</HTML>

37. Explain the components of Java Server Page.
Ans.
The components of a JSP, including directives, scripting, implicit
objects, and standard actions.
JSP Scripting:---
Scripting is a JSP mechanism for directly embedding Java code fragments
into an HTML page. Three scripting language components are involved in
JSP scripting. Each component has its appropriate location in the generated
servlet. This section examines these components.

And Read Question Number Ans :---- 18,19.

38. Explain the semantics of HTML FORM elements.
Ans.
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.

39. What are the advantages of using servlets to extend server
functionality?
Ans.
Following are the advantages of using servlets:
1. It helps to achieve platform independence.
2. It provides performance improvement as classes stays in the memory once
called.
3. It is much more secure over traditional server side languages. For example,
no problems of memory leakages and buffer overflows are faced in case of
servlets.
4. It uses Java's multithreading capabilities, which gives it a performance gain.

40. Explain the use of hidden controls in a web page with example.
Ans.
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>
<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>

41. Explain how to track users using SESSIONS, APPLICATIONS, and Java
beans.
Ans.
Session:- A session enables we to track one user at a time. During the time
a session is active, we can store data in the session, and it will be preserved
on the server in between times the user access our page. The default time
Tomcat allows between page accessses in a session in 30 minutes.we can
access the current session using the built in JSP session object, which is
based on the javax.servlet.http.HttpSession interface.
Application:- An pplication enables we to track all JSPs in same site., no
matterhow many users are usimg them. To accesss the current application,
we can use the built -in JSP appliction object. Like the session object, the
application object is based on the javax.servlet.http.HttpSesssion interface.
JavaBeans:- we can instruct JavaBeans in a session object as well as in
attributes.we can store javaBeans in application also. We do this with the
<jsp:useBean> elements scope attribute, which we can set to one of these
values: scope=page|request|session|application. The term scope indicates
where a data item is visible in your code. The default scope for a bean is page
scope, which means the bean exists only for the page scope. However, if you
set the scope of a bean to a session, it is stored with the rest of session's data

42. Explain the working of SSL.
Ans.
SSL has two distinct entities, server and client. The client is the entity that
initiates the transaction whereas the server is the entity that responds to the
client and negotiates which cipher suites are used for encryption. In SSL, the
Web browser is the client and the Web site server is the server. Three
protocols lie within SSL, the Handshake protocol, the Record protocol, and
the Alert protocol. The client authenticates the server during the Handshake
protocol. When the session is initiated and the handshake is complete, the
data transfer is encrypted during the Record Protocol phase. If there are any
alarms at any point during the session, the alert is attached to the
questionable packet and handled according to the Alert protocol.

43. What is EJB? List the advantages and disadvantages of EJB's.
Ans.
Enterprise Java Beans (EJB) is a managed, server-side component
architecture for modular construction of enterprise applications. - The EJB
specification is one of the several Java APIs in the Java Platform, Enterprise
Edition.- EJB is a server-side component that encapsulates the business logic
of an application. - are invoked by local or remote clients.EJB is a framework
for writing distributed programs.
ADVANTAGES: Many vendor application servers conform to the J2EE
specification allowing one to select a best-of-breed solution. l To handle
fluctuations in resource demand server-side resources can easily be scaled
by adding or removing servers. l Application servers provide access to
complex services, namely transaction and security management, resource
pooling, JNDI (Java Naming and Directory Interface), component lifecycle
management, etc.
Disadvantages : EJB has a large and complicated specification. l EJBs take
longer to develop. Also, when things go wrong they can be more difficult to
debug. occasionally the bug may not be in your code but in the application
server itself. l No sooner have you deployed your EJB application than you
see a new specification coming down the pipe with newer features, rendering
your application obsolete. This situation, however, is unavoidable with cutting-
edge technologies.

44. What is a war file? Give its importance.
Ans.
WAR or Web Application Archive file is packaged servlet Web application.
Servlet applications are usually distributed as a WAR files.

Você também pode gostar