Programming

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 15

Web Programming

Q1. Explain the two main ways that HTTP protocol to send information to a web
server.
Ans.GET method: The foundation of HTTP/0.9 (the first implementation of the HTTP
protocol)
was the definition of the GET method that was used by a web browser to request a
specific document.
POST method: The POST method allows web browsers to send an unlimited amount of
data to a web
server by allowing them to tag it on to an HTTP request after the request headers as the
message body.
Q2. How are JSPs better than servlets?
Ans. Java programming knowledge is needed to develop and maintain all aspects of the
application, since the
processing code and the HTML elements are lumped together. b) 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. c) Its hard
to take advantage of web-page development tools when designing the application
interface. If such tools are
used to develop the web page layout, the generated HTML must then be manually
embedded into the servlet
code, a process which is time consuming, error prone, and extremely boring. Adding JSP
to the puzzle we solve
these problems.So JSPs better than servlets
Q3. Explain GET and POST method.
Ans: When a client sends a request to the server, the clients can also additional
information with the URL to
describe what exactly is required as output from the server by using the GET method.
The additional sequence
of characters that are appended to URL is called a query string. However, the length of
the query string is
limited to 240 characters. Moreover, the query string is visible on the browser and can
therefore be a security risk.
to overcome these disadvantages, the POST method can be used. The POST method
sends the data as packets
through a separate socket connection. The complete transaction is invisible because to the
client. The disadvantage
of POST method is that it is slower compared to the GET method because data is sent to
the server as separate packets.
Q4. What is HTML? What is the use of HTML?
Ans. HTML (Hyper Text Markup Language) is simply a markup language, which is used
to describe the logical structure
of a document.
Q5. Describe the role of deployment descriptors.
Ans: This is an XML file describing the servlet and other components that make up your
application, along with any
initialization parameters and container-managed security constraints that we want the
server to enforce for us. The
ejb-jar.xml or application.xml file is used as deployment descriptor.

Q6. Explain document object model.


Ans: The Document Object Model, or DOM, is the interface that allows
programmatically accessing and manipulating
the contents of a web page or document. 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 us to create dynamic content
The DOM also provides an
interface for dealing with events, allowing to capture and respond to user or browser
actions. The Document Object
Model is the real core of dynamic HTML. It makes HTML changeable. The DOM is the
hierarchy of elements that are
present in the browser at any given time. DOM.
Q7. What is JSP? What is the use of JSP? OR What are the advantages of JSP?
Ans. JSP is stands for Java server Page. JSP is a technology for developing web page that
include dynamic content.
JSP is use for change
Q. What are the advantages of JSP?
Ans: 1) JSP supports both scripting- and element-based dynamic content and allows
programmers to develop
custom tag libraries to satisfy application-specific needs. 2) JSP pages are compiled for
efficient server processing.
3) JSP pages can be used in combination with servlets that handle the business logic, the
model supported by Java
servlet template engines.
Q9. Explain entity beans and session beans.
Ans: There are two kinds of Enterprise Java Beans, Entity Beans and Session Beans.
Entity Bean:
An entity bean is an object with special properties: a) It is permanent: an entity bean stays
around until
it is deleted. A program can create an entity bean then the program can be stopped and
restarted. b) It is
network based: an entity bean can be used by any program on the network. It is executed
remotely: an
entity bean run on a server machine. It is identified by a primary key: The primary key
is unique; each
entity bean is uniquely identified by its primary key.
Session Beans: Session beans are different from of entity beans in that they are not
permanent objects.
Session beans can be used to distribute and isolate processing tasks. Session bean can be
used to perform
a certain task on behalf of its client. The tasks can be distributed on different machines.
Session bean may
perform a task of remote location. Session beans do not have a primary key.
Q10. Explain the methods to access nodes in a document tree.
Ans: 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().
Q11. What is the difference between internet & intranet?
Ans. Internet -: Internet is global network of networks. Internet is a tool for
collaborating academic research,
and it has become a medium for exchanging and distributing information of all kinds. It is
an interconnection
between several computers of different types belonging to various networks all over
global.
Intranet -: Intranet is not global. It is a mini web that is limited to user machines and
software program of
particulars organization or company.
Q12. What are the different between session and application?
Ans: 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.
Q13. What is the difference between web server and application server?
Ans: 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, ejbjar.xml or
application.xml file is used as deployment descriptor.
Q14. Differentiate between Java & Java scripts.
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.

Q15. What is the difference between HTML and DHTML?


Ans: HTML: HTML stands for Hyper Text Markup Language. It is a language. HTML
cant be
done after the page loads. HTML can be or not used with JavaScript.
DHTML: DHTML stands for Dynamic Hyper Text Markup Language. DHTML isnt
really a
language or a thing in itself its just a mix of those technologies. Dynamic HTML is
simply HTML
that can change even after a page has been loaded into a browser. DHTML can be used
with JavaScript.
Q16. Discuss the difference between static and dynamic web pages.
Ans: a) The great numbers of web pages on the internet are static HTML pages but
visitors find dynamically
generated web pages because they are provide instant access to highly relevant
information. b) Static pages are
easily read by search engine spider, Dynamic sites are also easy to update. c) Static web
pages are simple text
files that are displayed by your browser upon request, Dynamic Web pages, contain little
actual text. They are
created each time they are requested, retrieving information from a database.
Q17. What is an application server?
Ans: 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 we can deploy a java components
ranging from simple java
application to server side business components like EJBs
Q18. Explain briefly about cascading style sheets (CSS).
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>
Q19. What are the advantages and disadvantages of EJBs?
Ans: Advantage of EJB: a) Many vendor application servers conform to the J2EE
specification allowing
one to select a best-of-breed solution. b) To handle fluctuations in resource demand
server-side resources
can easily be scaled by adding or removing servers. c) Application servers provide access
to complex
services, namely transaction and security management, resource pooling, JNDI,
component lifecycle
management, etc.

Disadvantage of EJB: a) EJB has a large and complicated specification.


b) EJBs take longer to develop. Also, they can be more difficult to debug. c) No sooner
have we deployed
our EJB application than we see a new specification coming down the pipe with newer
features, rendering
our application obsolete. This situation, however, is unavoidable with cutting-edge
technologies.
Q20. What is CGI? Give example of CGI applications and explain anyone of them.
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 oraperl 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.
Q21. What is SSL? Why do you require SSL?
Ans: SSL stands for Secure Sockets Layer. SSL is a protocol. It is developed by
Netscape, has become
the universal standard on the Web for authenticating Web sites to Web browser users, and
for encrypting
communications between browser users and Web servers.We required SSL is to provide
security for
Web traffic. Security includes confidentiality, message integrity, and authentication. SSL
is built into
all major browsers and Web servers, simply installing a digital certificate, or Server ID,
enables SSL capabilities.

Q22. Explain how HTTP is used in client/server system. Further, Justify HTML is a
language of the web.
Ans: HTTP is a request-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 eager way of distributing information
across information
systems like LAN, WAN, or the Internet. A client/server system works something like
this: 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. HTML is
a simply markup
language used to define a logic structure rather than computer. The beauty of HTML of
route is that it is
generic enough that it can be read and interpreted by a web browser running on any
machine or o/s. It
only focuses on describing is responsible for adding style. So that HTML is the language
of the web.
Q23. What is EJB and give the advantage of EJB.
Ans: An EJB is a server-side component that executes specific business logic. EJBs run
on a server and
are invoked by local or remote clients. Advantage of EJB: a) Many vendor application
servers conform to
the J2EE specification allowing one to select a best-of-breed solution. b) To handle
fluctuations in resource
demand server-side resources can easily be scaled by adding or removing servers. c)
Application servers
provide access to complex services, namely transaction and security management,
resource pooling, JNDI
(Java Naming and Directory Interface), component lifecycle management, etc.
Q24. Explain the several ways of tracking users.
Ans: The several Ways of tracking users are followings:
Hidden text: It is easier way to associating information which is not directly associated
to user.
Cookies: -This is probably the most common way of tracking users on the Internet. We
can store information
in a users computer using cookies, and retrieve it when we need it. We can also specify
how long the cookie
should exist before being deleted by the browser.
Sessions: -Sessions 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. Preserve data between accesses to a Web page
by the same user.
Application:- Data can be shard using application can be used to track multiple users at
same time.
Q25. Briefly explain 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 wellpresented 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.
Q26. How do you create a Cookie? Explain with an example.
Ans: Cookies is the way to store information in users computer and retrieve it when we
need it. Cookies are
small text file that used by a webserver to keep tracking of users. A cookie has value in
the form of key-value pair.
They are created by user and sent to the client with the HTTP response headers. The
client saves the cookies in the
local disk and sends them along with the HTTP request headers to the server. To create
the cookies, we use the
cookies class, constructor, packing it the name of the cookie and test in the cookie. We
can also set length of time
the cookie will exits on the users computer with set MaxAge method.
We pass value in second to make the cookie last for a day we can pass a value of
24*60*60 in this way.
<HTML><HEAD> <TITLE>Setting a Cookie</TITLE> </HEAD><BODY>
<H1>Hello Cookie</H1>
<% Cookie cookie1 = new Cookie("message", "Hello!"); cookie1.setMaxAge(24 * 60 *
60);
response.addCookie(cookie1); %> </BODY> </HTML>
Q27. What is XML? Explain in brief.
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.: <? xml version=1.0?>
<authors><author><firstname>raj</firstname><lastname><kumar</lastname></author>
</authers>
Q28. What is Java script? What is the use of Java script and what are its
disadvantages?
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.
The uses of JavaScript are: i) Control Document Appearance and Content ii) Control
the Browser
iii) Interact with Document Control iv) Interact with User v) Read and Write Client
State with Cookies
vi) Interact with Applets vii) JavaScript is only used inside of HTML documents.
Disadvantages: i) JavaScript do not have any graphics capabilities.
ii) For security reasons, client-side JavaScript does not allow the reading or writing of
files.
iii) JavaScript does not support any kind of networking.
iv) JavaScript doesnt have any multithreading capabilities.
Q29. Explain two 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, $username, and $url are all examples of scalar variable names. A scalar
can hold data of any
type, be it a string, a number, or whatnot. We can also use scalars in double-quoted
strings: my $fnord = 23;
my $blee = The magic number is $fnord.; Now if you print $blee, we will get The
magic number is 23.
Perl interpolates the variables in the string, replacing the variable name with the value of
that variable.
Arrays: 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 a @-sign. e.g.:
my @colors = (red,green,blue); foreach my $i (@colors) { print $i\n; }
Q30. What are the advantages of using servlet?
Ans: the servlet to take advantage of HTTP connection keep alive. If content length
can not be set in advance,
the performance penalties associated with not using keep alive will sometimes be avoided
if the response entity
fits in an internal buffer. Servlet has all the advantages like platform and vendor
independence, integration,
efficiency, scalability, robustness, and security.
Q31. Explain in brief the building block of web.
Ans: There are two most important building blocks of web: 1) 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.
Q32. What is CGI? Give example of CGI applications and explain anyone of them.
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 oraperl 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.
Q33. What is JSP? How it is different from CGI programming?
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. A
JSP page contains
standard markup language elements, such as HTML tags, just like a regular web page.
JSP also contains special
JSP elements that allow the server to insert dynamic content in the page. JSP elements
can be used for a variety
of purposes, such as retrieving information from a database or registering user
preferences. JSP defines a number
of standard elements that are useful for any web application.
Q34. What are the disadvantages of hidden controls?
Ans: Storing data in hidden controls works, it is not very secure, and the data stored in
those controls
is visible if the user views the pages HTML source. We cant store data between
sessions.
Q35. Explain briefly the uses of Java Scripts.
Ans: JavaScript is a Client - Side Scripting. JavaScript changes the font size or any
other
CSS property on an element. So JavaScript plays a really big role in DHTML.
Q36.Summarize salient features of HTTP protocol.
Ans: HTTP is a protocol that is defined in several RFCs located
at the Internic. HTTP is a
request-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
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.

Q37.With syntax explain the five TYPE attribute that INPUT tag defines.
Ans: 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:
1) 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">

2) INPUT TYPE=CHECKBOX: A checkbox is a toggle that the user can


select (switch on) or deselect (switch off.) Syntax : <INPUT TYPE=CHECKBOX
-CHECKED NAME=name -ONCLICK=JScode -VALUE=checkboxValue>
3) INPUT TYPE=FILE: This places an element on an HTML form that lets the user
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" >
4) INPUT TYPE=HIDDEN: A hidden input element is an invisible element whose
main
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" >
5) INPUT TYPE=SUBMIT: When a user clicks a submit button, the form is
submitted,
which means that the ACTION specified for the form is invoked. Syntax: <INPUT TYPE
="SUBMIT" -NAME=" name" -VALUE=" value" >
6) INPUT TYPE=PASSWORD: A password element is a text input field in which
each
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 >
Q38.Explain in brief ordered list tags.
Ans: 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>
Q39.Explain CGI - Pm module with an example
Ans: Perl offers a powerful feature to programmers: add-on modules. These are
collections
of pre-written code that can use to do all kinds of tasks. We can save the time and trouble
of reinventing the wheel by using these modules. Some modules are included as part of
the
Perl distribution; these are called standard library modules and dont have to be installed.
Were not doing use CGI.pm but rather use CGI. The .pm is implied in the use statement.
The qw(:standard) part of this line indicates that we are importing the standard set of
function from CGI.pm.
#!/usr/bin/perl wT -use CGI qw(:standard);-print header;-print start_html(Hello
World);-print <h2>Hello,

world!</h2>\n;-print end_html; CGI.pm also has a number of functions that serve as


HTML shortcuts.
Q40. What is a webserver? Explain.
Ans: The Web server is software. It is responsible for accepting browser requests,
retrieving the specified file, and returning its contents. Web servers first retrieve the
request using Berkeley sockets. The Web server listens for
requests on a particular
port on the server machine. Once the
server receives the request, it locates the
document being requested. It looks for the
file under the document root directory.
The server sends the contents of the file
back to the client. By default web browsers
use port no. 80 for their requests. Once 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.The server sends the contents of the file back to the client,
along with some
HTTP response headers. Among the data in the response headers is the media type (also
known as a
content type or MIME type), i.e., the format that the file is in.
Q41.Explain JSP error handling.
Ans: Like all development methods, JSPs need a dynamic mechanism for handling errors.
The JSP architecture provides an error-handling solution through the use of JSPs that are
written exclusively to handle JSP errors. The errors that occur most frequently are
runtime
errors that can arise either in the body of the JSP page or in some other object that is
called
from the body of the JSP page. Request-time errors that result in an exception being
thrown
can be caught and handled in the body of the calling JSP, which signals the end of the
error.
Exceptions that are not handled in the calling JSP result in the forwarding of the client
request,
including the uncaught exception, to an error page specified by the offending JSP. Here
we
see how an error page works, lets create a simple JSP that throws an uncaught
exception.
The JSP shown here uses the error page created in the previous section.
<%@ page errorPage=errorpage.jsp %><%if ( true ) { throw new Exception(An
uncaught
Exception);}%> In this listing that the first line of code sets errorPage equal to
errorpage.jsp,
which is the name of the error page. To make a JSP aware of an error page,we simply
need to add the
errorPage attribute to the page directive and set its value equal to the location of our JSP
error page.
Q42. Explain any three method of the javax.servlet.http.HttpSession interface.

Ans. a) void addCookie(Cookie cookie): -Adds the specified cookie to the response
object
b) java.util.Enumeration getAttributeNames(): -Returns Java Enumeration of String
objects containing
the names of all the objects in this session.
c) long getCreationTime(): -Returns the time when this session was created (measured
in
milliseconds since midnight January 1, 1970 GMT).
d) long getLastAccessedTime(): -Returns the last time the client sent a request in
with this session, as the number of milliseconds since midnight January 1, 1970 GMT.
e) int getMaxInactiveInterval(): - Returns the maximum time, in seconds, which the
server will keep this session open between client accesses.
f) void removeAttribute(java.lang.String name): -Removes the object with
the specified name from this session.
Q43. What do you mean by scriptlets in JSP?
Ans: Scriptlets are the JSP components that bring all the JSP elements together.
They can contain almost any coding statements that are valid for the language
referenced in the language directive. They are executed at request time, and they
can make use of all the JSP components. The syntax for a scriptlet is as follows:
<% scriptlet source %>
Q44.What is SSL? What is the necessity of it? Explain the working of SSL.
Ans: SSL stands for
Secure Sockets Layer.
SSL is a protocol. It is developed by
Netscape, has become the
universal standard on the
Web for authenticating
Web sites to Web browser
users, and for encrypting
communications between browser users and Web servers. The main role of SSL
is to provide security for Web traffic. Security includes onfidentiality, message
integrity, and authentication. The working of SSL is: 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.
Q45. Write a JavaScript program to pop up an alert message.
Ans: <HTML> <HEAD> <Script language=Java Script> alert (This is an alert
message for java script)
</SCRIPT></HEAD><BODY></BODY></HTML>
Q46.Explain in brief how to use hidden controls in a web page. Give an example.
Further,
list the advantages and disadvantages of hidden controls.
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
Disadvantages: Storing data in hidden controls is not very secure. The data stored in
those
controls is visible if the user views the pages HTML source. We cant store data
between sessions.
Q47.Explain the ordered lists and unordered lists.
Ans: Ordered lists: The OL tag displays an ordered, or numbered, list. The default
numbering
style is determined by the browser, but you 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>.
Unordered list: The UL tag displays a bulleted list. You can use the tags TYPE
attribute to change the bullet style. Use the LI tag to designate the individual list items in
the list.
Syntax: <UL TYPE="CIRCLE"|"DISC"|"SQUARE" -CLASS="styleClass"
ID="namedPlaceOrStyle"LANG= ISO -STYLE=style > </UL>.
Q48.Write HTML script to display Hello world, welcome to the
world of HTML, the title as world of HTML.
Ans: <HTML><HEAD><TITLE>world of HTML</TITLE><Script language=Java
Script>
Hello world, welcome to the world of HTML</SCRIPT></HEAD><BODY></BODY>
</HTML>
Q49.Write a JSP program which displays different message to the user based on the
time of day.
Ans: <%@ taglib prefix=c uri=http://java.sun.com/jstl/core %> <html> <body
bgcolor=white>
<jsp:useBean id=clock class=java.util.Date /> <c:choose><c:when test=$
{clock.hours < 12}>
<h1>Good morning!</h1></c:when><c:when test=${clock.hours < 18}><h1>Good
day!</h1>
</c:when><c:otherwise><h1>Good evening!</h1></c:otherwise></c:choose>Welcome
to our site, open 24 hours a day.</body></html>.

Q50.With diagram explain the life-cycle of Servlet in briefly.


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.
Service - This is the third state in the servlet lifecycle. In this state the servlets
service() method is called which generates response.

i)

Setting the content type of the response. The receiving application


(browser) uses this information to know how to treat the response data.
ii)
Print Writer is a class from java.io package that extends the
java.io.writer abstract class.
iii)
We can use meta tags in the HTML generated to indicate browser not
to cache page and some of the similar tasks.
Destroy - This is the final stage in a servlet lifecycle. In this stage destroy()
method is called before shutting down the servlet.
Q51.What is servlets? Give the Basic servlet structure.
Ans: Servlets are programs that run on a Web server and build Web pages.
The outline of a basic servlet that handles GET requests. GET requests, are requests
made by browsers when the user types in a URL on
the address line, follows a link from a Web page, or
makes an HTML form that does not specify a
METHOD. Servlets can also very easily handle
POST requests, which are generated when someone
creates an HTML form that specifies
METHOD=POST. A class should extend
HttpServlet and override doGet or doPost, depending
on whether the data is being sent by GET or by
POST. These methods take two arguments: HttpServletRequest and HttpServletResponse.
HttpServletRequest has methods that find out about incoming information such as FORM
data, HTTP request headers. HttpServletResponse has methods that specify the HTTP
response line response, PrintWriter used to headers and most importantly, obtain a send
output back to the client. For simple servlets, most of the effort is spent in println
statements that generate the desired page. We have to import classes in java.io ,
javax.servlet , and javax.servlet.http. DoGet and doPost are called by the service method,
and sometimes we want to override service directly.
Q52.Explain the tags that use to design table.
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. We 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.

You might also like