Você está na página 1de 10

Web Programming Ans.

HTML (Hyper Text Markup Language) is simply


Q1. Explain the two main ways that HTTP protocol a markup language, which is used to describe the
to send information to a web server. logical structure
Ans.GET method: The foundation of HTTP/0.9 (the of a document.
first implementation of the HTTP protocol)
was the definition of the GET method that was used by Q5. Describe the role of deployment descriptors.
a web browser to request a specific document. Ans: This is an XML file describing the servlet and
POST method: The POST method allows web other components that make up your application, along
browsers to send an unlimited amount of data to a web with any initialization parameters and container-
server by allowing them to tag it on to an HTTP request managed security constraints that we want the server to
after the request headers as the message body. enforce for us. The ejb-jar.xml or application.xml file
is used as deployment descriptor.
Q2. How are JSPs better than servlets?
Ans. Java programming knowledge is needed to Q6. Explain document object model.
develop and maintain all aspects of the application, Ans: The Document Object Model, or DOM, is the
since the interface that allows programmatically accessing and
processing code and the HTML elements are lumped manipulating the contents of a web page or document.
together. b) Changing the look and feel of the It provides a structured, object-oriented representation
application, of the individual elements and content in a page with
or adding support for a new type of client, requires the methods for retrieving and setting the properties of
servlet code to be updated and recompiled. c) It’s hard those objects. It also provides methods for adding and
to take advantage of web-page development tools when removing such objects, allowing us to create dynamic
designing the application interface. If such tools are content The DOM also provides an interface for dealing
used to develop the web page layout, the generated with events, allowing to capture and respond to user or
HTML must then be manually embedded into the browser actions. The Document Object
servlet Model is the real core of dynamic HTML. It makes
code, a process which is time consuming, error prone, HTML changeable. The DOM is the hierarchy of
and extremely boring. Adding JSP to the puzzle we elements that are present in the browser at any given
solve time. DOM.
these problems.So JSPs better than servlets
Q7. What is JSP? What is the use of JSP? OR What
Q3. Explain GET and POST method. are the advantages of JSP?
Ans: When a client sends a request to the server, the Ans. JSP is stands for Java server Page. JSP is a
clients can also additional information with the URL to technology for developing web page that include
describe what exactly is required as output from the dynamic content.
server by using the GET method. The additional JSP is use for change
sequence Q. What are the advantages of JSP?
of characters that are appended to URL is called a query Ans: 1) JSP supports both scripting- and element-based
string. However, the length of the query string is dynamic content and allows programmers to develop
limited to 240 characters. Moreover, the query string is custom tag libraries to satisfy application-specific
visible on the browser and can therefore be a security needs. 2) JSP pages are compiled for efficient server
risk. processing.
to overcome these disadvantages, the POST method can 3) JSP pages can be used in combination with servlets
be used. The POST method sends the data as packets that handle the business logic, the model supported by
through a separate socket connection. The complete Java
transaction is invisible because to the client. The servlet template engines.
disadvantage
of POST method is that it is slower compared to the Q9. Explain entity beans and session beans.
GET method because data is sent to the server as Ans: There are two kinds of Enterprise Java Beans,
separate packets. “Entity Beans” and “Session Beans”. Entity Bean:
An entity bean is an object with special properties: a) It
Q4. What is HTML? What is the use of HTML? 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 Ans: Web server: Web server is the software
program on the network. It is executed remotely: an responsible for accepting browser requests, retrieving
entity bean run on a “server” machine. It is identified its
by a primary key: The primary key is unique; each content & returning its content. By default, Web
entity bean is uniquely identified by its primary key. browsers use port 80 for their requests. Web servers are
Session Beans: Session beans are different from of often called httpd, using a UNIX convention in which
entity beans in that they are not permanent objects. daemons are named with the name of the service
Session beans can be used to distribute and isolate followed by the letter “d”. Web servers first retrieve the
processing tasks. Session bean can be used to perform request using Berkeley sockets.
a certain task on behalf of its client. The tasks can be Most web servers on Internet today run on UNIX
distributed on different machines. Session bean may machines.
perform a task of remote location. Session beans do not Application server: An application server commonly
have a primary key. includes a web server so perhaps we can see an
application server as an extension of a web server. In
Q10. Explain the methods to access nodes in a application server you can deploy a java components
document tree. ranging from simple java application to server side
Ans: methods for accessing and creating other nodes in business components. Usually when we want to deploy
the document tree. Some methods are: EJBs we will go for App servers like web-logic or web-
getElementById(), getElementsByTagName(), sphere. In application server, ejb-jar.xml or
createElement(), createAttribute(), createTextNode(). application.xml file is used as deployment descriptor.
All of the above methods (except
getElementsByTagName()) can only be used against Q14. Differentiate between Java & Java scripts.
the document Java -:Java Programming language,is an OOP
object, i.e., using the syntax : document.methodName(). Language and development environment, application
environment, deployment environment. It is standalone
Q11. What is the difference between internet & programming Language that do not require a web
intranet? browser to execute.
Ans. Internet -: Internet is global network of networks. Java script: It is a contained in the HTML source of
Internet is a tool for collaborating academic research, webpage. It controls document appearance and content.
and it has become a medium for exchanging and It also manipulates embedded images and it also
distributing information of all kinds. It is an interacts with Applets. Its advantage is that it is
interconnection simplified,
between several computers of different types belonging it doesn’t have to be compiled and the source code
to various networks all over global. resides within our HTML document.
Intranet -: Intranet is not global. It is a mini web that is
limited to user machines and software program of Q15. What is the difference between HTML and
particulars organization or company. DHTML?
Ans: HTML: HTML stands for Hyper Text Markup
Q12. What are the different between session and Language. It is a language. HTML can’t be
application? done after the page loads. HTML can be or not used
Ans: Sessions—Sessions are something the server with JavaScript.
offers us to support user tracking, and they’re great, DHTML: DHTML stands for Dynamic Hyper Text
although they can take up a lot of resources on the Markup Language. DHTML isn’t really a
server. Sessions preserve data between accesses to a language or a “thing” in itself it’s just a mix of those
Web page by the same user. technologies. Dynamic HTML is simply HTML
Applications—Applications are much like sessions, as that can change even after a page has been loaded into a
we’ll see, but they’re more general— browser. DHTML can be used with JavaScript.
we can share data between all the JSP pages in a site
using applications. In other words, unlike Q16. Discuss the difference between static and
sessions, applications can be used to track multiple dynamic web pages.
users at the same time. Ans: a) The great numbers of web pages on the internet
are static HTML pages but visitors find dynamically
Q13. What is the difference between web server and
application server?
generated web pages because they are provide instant Q20. What is CGI? Give example of CGI
access to highly relevant information. b) Static pages applications and explain anyone of them.
are Ans: CGI or “Common Gateway Interface” is a
easily read by search engine spider, Dynamic sites are specification which allows web users to run programs
also easy to update. c) Static web pages are simple text from
files that are displayed by your browser upon request, their computer. CGI is the part of the Web server that
Dynamic Web pages, contain little actual text. They are can communicate with other programs running on the
created each time they are requested, retrieving server. The Web server can call up a program, while
information from a database. passing user-specific data to the program. The program
then processes that data and the server passes the
Q17. What is an application server? program’s response back to the Web browser. Some of
Ans: An application server commonly includes a web the possible applications of CGI are:
server so perhaps we can see an application server 1) Forms: - One of the most prominent uses of CGI is in
as an extension of a web server. In application server processing forms are subsets of HTML that allow
we can deploy a java components ranging from simple the user to supply information forms. The forms
java interface makes Web browsing an interactive process
application to server side business components like for
EJBs the user and the provider.
2) Gateways: - CGI provides a solution to the problem
Q18. Explain briefly about cascading style sheets in the form of a gateway. We can use a language
(CSS). such as oraperl or a DBI extension to Perl to form SQL
Ans: CSS stands for Cascading style sheets. CSS is the queries to read the information contained within
part of DHTML that controls the look and placement the database. Once we have the information, we can
of the elements on a page. With CSS we can basically format and send it to the client. In this case, the
set any style property of any element on a HTML page. CGI program servers as a gateway to the Oracle
One of the biggest advantages with CSS instead of the database. 3) Virtual Documents: - Virtual, or dynamic,
regular way of changing the look of elements is that document creation is at the heart of CGI. They are
we split content from design. If we want to change like created on the fly in response to a user’s information
the font size of our main text we just change it in the request. We can create virtual HTML, plain text, image,
CSS file and all pages are updated. In CSS program and even audio documents.
always place the style tag inside the head of document. b) In brief explain two types of PEARL variables.
The syntax for CSS code is: <style type=”text/css”>
Element{property1:value;property:value2} </style> Q21. What is SSL? Why do you require SSL?
Ans: SSL stands for Secure Sockets Layer. SSL is a
Q19. What are the advantages and disadvantages of protocol. It is developed by Netscape, has become
EJBs? the universal standard on the Web for authenticating
Ans: Advantage of EJB: a) Many vendor application Web sites to Web browser users, and for encrypting
servers conform to the J2EE specification allowing communications between browser users and Web
one to select a best-of-breed solution. b) To handle servers.We required SSL is to provide security for
fluctuations in resource demand server-side resources Web traffic. Security includes confidentiality, message
can easily be scaled by adding or removing servers. c) integrity, and authentication. SSL is built into
Application servers provide access to complex all major browsers and Web servers, simply installing a
services, namely transaction and security management, digital certificate, or Server ID, enables SSL
resource pooling, JNDI, component lifecycle capabilities.
management, etc.
Disadvantage of EJB: a) EJB has a large and
complicated specification.
b) EJBs take longer to develop. Also, they can be more Q22. Explain how HTTP is used in client/server
difficult to debug. c) No sooner have we deployed system. Further, Justify “HTML is a language of the
our EJB application than we see a new specification web”.
coming down the pipe with newer features, rendering Ans: HTTP is a “request-response” type protocol that
our application obsolete. This situation, however, is specifies that a client will open a connection to a
unavoidable with cutting-edge technologies. 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) Q25. Briefly explain role played by CGI
so that they can communicate with each other and programming in web programming.
exchange files. Client/server system is a very eager way Ans: CGI stands for Common Gateway Interface. CGI
of distributing information across information is the part of the Web server that can communicate
systems like LAN, WAN, or the Internet. A with other programs running on the server. CGI
client/server system works something like this: A server provides a “gateway” between a human user with
sits in some office somewhere with a bunch of files that unexpected
people might want access to. This computer runs and complex needs, and a powerful, command/logic
a software package that listens all day long to requests oriented server. All CGI applications must translate the
over the wires. The “server software” will then needs of clients into server requests, and translate
accesses the server hardware, find the requested file, server replies into meaningful well-presented
send it back over the wires to the “client” who “answers”. The
requested it, and then wait for another request from the CGI script will be responsible for processing the form
same or another client. HTML is a simply markup data, which is filled by user and responding to the client
language used to define a logic structure rather than in the form of dynamically generated HTML. With
computer. The beauty of HTML of route is that it is CGI, the Web server can call up a program, while
generic enough that it can be read and interpreted by a passing
web browser running on any machine or o/s. It user-specific data to the program (such as what host the
only focuses on describing is responsible for adding user is connecting from, or input the user has supplied
style. So that HTML is the language of the web. using HTML form syntax). The program then processes
that data and the server passes the program’s response
Q23. What is EJB and give the advantage of EJB. back to the Web browser.
Ans: An EJB is a server-side component that executes
specific business logic. EJBs run on a server and Q26. How do you create a Cookie? Explain with an
are invoked by local or remote clients. Advantage of example.
EJB: a) Many vendor application servers conform to Ans: Cookies is the way to store information in user’s
the J2EE specification allowing one to select a best-of- computer and retrieve it when we need it. Cookies are
breed solution. b) To handle fluctuations in resource small text file that used by a webserver to keep tracking
demand server-side resources can easily be scaled by of users. A cookie has value in the form of key-value
adding or removing servers. c) Application servers pair.
provide access to complex services, namely transaction They are created by user and sent to the client with the
and security management, resource pooling, JNDI HTTP response headers. The client saves the cookies in
(Java Naming and Directory Interface), component the
lifecycle management, etc. local disk and sends them along with the HTTP request
headers to the server. To create the cookies, we use the
Q24. Explain the several ways of tracking users. cookies class, constructor, packing it the name of the
Ans: The several Ways of tracking users are cookie and test in the cookie. We can also set length of
followings: time
Hidden text: It is easier way to associating information the cookie will exits on the user’s computer with set
which is not directly associated to user. MaxAge method.
Cookies: -This is probably the most common way of We pass value in second to make the cookie last for
tracking users on the Internet. We can store information a day we can pass a value of 24*60*60 in this way.
in a user’s computer using cookies, and retrieve it <HTML><HEAD> <TITLE>Setting a
when we need it. We can also specify how long the Cookie</TITLE> </HEAD><BODY>
cookie <H1>Hello Cookie</H1>
should exist before being deleted by the browser. <% Cookie cookie1 = new Cookie("message",
Sessions: -Sessions are something the server offers us "Hello!"); cookie1.setMaxAge(24 * 60 * 60);
to support user tracking, and they’re great, although response.addCookie(cookie1); %> </BODY>
they </HTML>
can take up a lot of resources on the server. Preserve
data between accesses to a Web page by the same user. Q27. What is XML? Explain in brief.
Application:- Data can be shard using application can Ans: Extensible markup language is a text-based
be used to track multiple users at same time. markup language that enables to store data in a
structured format
by using meaningful tags. XML is a cross-platform, h/w so for example, $username, and $url are all examples of
& s/w independent markup language. XML allows scalar variable names. A scalar can hold data of any
computers type, be it a string, a number, or whatnot. We can also
to store data in a format that can be interpreted by any use scalars in double-quoted strings: my $fnord = 23;
other computer system. XML can be used to transfer my $blee = “The magic number is $fnord.”; Now if
structured you print $blee, we will get “The magic number is 23.”
data between various systems. Xml is used as a Perl interpolates the variables in the string, replacing
common data interchanges format in a number of the variable name with the value of that variable.
applications. Arrays: An array stores an ordered list of values. While
XML is extremely simple. XML represents a scalar variable can only store one value, an array can
information as text using tags to add structure. A tag store
begins with a many. Perl array names are prefixed with a @-sign.
name sandwiched between less-than (<) and greater- e.g.:
than (>) characters. my @colors = (“red”,”green”,”blue”); foreach my $i
Advantages of XML: a) it provides a way (@colors) { print “$i\n”; }
of creating domain-specific vocabulary.
b) It enables smart searches. Q30. What are the advantages of using servlet?
c) It provides user-selected view of data. Ans: the servlet to take advantage of HTTP
d) it allows granular updates. “connection keep alive”. If content length can not be set
XMl Document- <?xml version=”1.0" encoding=”UTF- in advance,
8"?><MyDocument></MyDocument> the performance penalties associated with not using
e.g.: <? xml version=”1.0”?> keep alive will sometimes be avoided if the response
<authors><author><firstname>raj</firstname><lastna entity
me><kumar</lastname></author></authers> fits in an internal buffer. Servlet has all the advantages
like platform and vendor independence, integration,
Q28. What is Java script? What is the use of Java efficiency, scalability, robustness, and security.
script and what are its disadvantages?
Ans: JavaScript is a scripting language (like a simple Q31. Explain in brief the building block of web.
programming language). JavaScript is a language that Ans: There are two most important building blocks of
can be web: 1) HTML and 2) HTTP.
used for client-side scripting. JavaScript is only used HTML: - HTML stands for Hyper Text Markup
inside of HTML documents. With JavaScript, we can Language. HTML is a very simple language used to
make “describe”
text scroll across the screen like ticker tape. the logical structure of a document. Actually, HTML is
The uses of JavaScript are: i) Control Document often called programming language it is really not.
Appearance and Content ii) Control the Browser Programming languages are “Turing-complete”, or
iii) Interact with Document Control iv) Interact with “computable”. That is, programming languages can be
User v) Read and Write Client State with Cookies used
vi) Interact with Applets vii) JavaScript is only used to compute something such as the square root of pi or
inside of HTML documents. some other such task. Typically programming
Disadvantages: i) JavaScript do not have any graphics languages
capabilities. use conditional branches and loops and operate on data
ii) For security reasons, client-side JavaScript does not contained in abstract data structures. HTML is much
allow the reading or writing of files. easier than all of that. HTML is simply a ‘markup
iii) JavaScript does not support any kind of networking. language’ used to define a logical structure rather than
iv) JavaScript doesn’t have any multithreading compute anything.
capabilities. HTTP: - HTTP is a “request-response” type protocol. It
is a language spoken between web browser (client
Q29. Explain two different types of PEARL software)
variables. and a web server (server software) so that can
Ans: Perl has three types of variables: scalars, arrays, communicate with each other and exchange files. Now
and hashes. let us
Scalars: A scalar variable stores a single (scalar) value.
Perl scalar names are prefixed with a dollar sign ($),
understand how client/server system works using standard markup language elements, such as HTML
HTTP. A client/server system works something like tags, just like a regular web page. JSP also contains
this: special
A big piece of computer (called a server) sits in some JSP elements that allow the server to insert dynamic
office somewhere with a bunch of files that people content in the page. JSP elements can be used for a
might want access to. This computer runs a software variety
package that listens all day long to requests over the of purposes, such as retrieving information from a
wires. database or registering user preferences. JSP defines a
number
Q32. What is CGI? Give example of CGI of standard elements that are useful for any web
applications and explain anyone of them. application.
Ans: CGI or “Common Gateway Interface” is a
specification which allows web users to run programs Q34. What are the disadvantages of hidden
from their controls?
computer. CGI is the part of the Web server that can Ans: Storing data in hidden controls works, it is not
communicate with other programs running on the very secure, and the data stored in those controls
server. is visible if the user views the page’s HTML source.
The Web server can call up a program, while passing We can’t store data between sessions.
user-specific data to the program. The program then
processes Q35. Explain briefly the uses of Java Scripts.
that data and the server passes the program’s response Ans: JavaScript is a Client - Side Scripting. JavaScript
back to the Web browser. changes the font size or any other
Some of the possible applications of CGI are: CSS property on an element. So JavaScript plays a
1) Forms: - One of the most prominent uses of CGI is really big role in DHTML.
in processing forms are subsets of HTML that
allow the user to supply information forms. The forms Q36.Summarize salient features of HTTP protocol.
interface makes Web browsing an interactive process Ans: HTTP is a protocol that is
for the defined in several RFC´s located
user and the provider. at the Internic. HTTP is a
2) Gateways: - CGI provides a solution to the problem “request-response” type protocol
in the form of a gateway. We can use a language such that specifies that a client will
as oraperl or a DBI extension to Perl to form SQL open a connection to a server
queries to read the information contained within the then send a request using a very
database. specific format. HTTP is a
Once we have the information, we can format and send language spoken between our
it to the client. In this case, the CGI program servers as web browser (client s/w) and a web server (server
a gateway to the Oracle database. software) so that they can communicate with each other
3) Virtual Documents: - Virtual, or dynamic, and exchange files. Client/server system is a very keen
document creation is at the heart of CGI. They are way of distributing information across information
created on the fly systems like a local area network (LAN), a wide area
in response to a user’s information request. We can network (WAN), or the Internet. A client/server system
create virtual HTML, plain text, image, and even audio works something like this: A big hunk of computer
documents. (called a server) sits in some office somewhere with a
bunch of files that people might want access to. This
Q33. What is JSP? How it is different from CGI computer runs a software package that listens all day
programming? long to requests over the wires. The “server software”
Ans: JSP stands for Java Server Pages. It is a will then accesses the server hardware, find the
technology for developing web pages that include requested file, send it back over the wires to the “client”
dynamic content. who requested it, and then wait for another request from
A JSP page can change its content based on any number the same or another client. The client software however,
of variable items, including the identity of the user, the deals with all the underlying client/server protocol stuff
user’s browser type, information provided by the user, and then displays the document. Web programming is a
and selections made by the user. A JSP page contains game of getting user input, processing that input, and
returning a dynamic response.
Syntax: <INPUT TYPE="PASSWORD"
-MAXLENGTH="maxChar” -NAME
="name" -ONSELECT="JScode "-SIZE="charLength"
Q37.With syntax explain the five TYPE attribute -VALUE="textValue” >
that INPUT tag defines.
Ans: The INPUT tag defines a form element that can Q38.Explain in brief ordered list tags.
receive user input. The TYPE attribute Ans: The OL tag displays an ordered, or numbered, list.
determines the specific sort of form element to be The default numbering
created. TYPE can be one of the following: style is determined by the browser, but we can use the
1) INPUT TYPE=”BUTTON”: A button appears in tag’s TYPE attributes to
the form. We must specify JavaScript change the numbering sequence and numbering style.
code as the value of the ONCLICK attribute to Use the LI tag to designate the
determine what happens when the user clicks the individual list items. Syntax : <OL -START="value"
button. - TYPE= "A"|"a"|"I"|"i"|"1" -CLASS= "styleClass”
Syntax :< INPUT TYPE="BUTTON" -ID="namedPlaceOrStyle"
-NAME="buttonName" -VALUE=" buttonText" –LANG=”ISO” -STYLE=”style” > </OL> Example:
ONCLICK=" JScode"> The following example
2) INPUT TYPE=”CHECKBOX”: A checkbox is a uses the LI tag to define three list elements in an
toggle that the user can ordered list. The numbers are
select (switch on) or deselect (switch off.) Syntax : shown as roman numerals and the first item has the
<INPUT TYPE=”CHECKBOX” number three.
-CHECKED NAME=”name” -ONCLICK=”JScode” <P>The following steps outline how to create HTML
-VALUE=”checkboxValue”> files :</P> <OL START="3" TYPE="I">
3) INPUT TYPE=”FILE”: This places an element on <LI> Use a text editor or Netscape Composer to create
an HTML form that lets the user our HTML file.<LI> Put the HTML files
supply a file as input. When the form is submitted, the on a web server.<LI> Test the files by viewing them in
content of the specified file is sent to a web browser.</OL>
the server as the value portion of the name/value pair
for this input element. Syntax :< INPUT Q39.Explain CGI - Pm module with an example
TYPE="FILE" -NAME=" name" -VALUE=" Ans: Perl offers a powerful feature to programmers:
filename" > add-on modules. These are collections
4) INPUT TYPE=”HIDDEN”: A hidden input of pre-written code that can use to do all kinds of tasks.
element is an invisible element whose main We can save the time and trouble
purpose is to contain data that the user does not enter. of reinventing the wheel by using these modules. Some
This data gets sent to the invoked CGI modules are included as part of the
program when the form is submitted. Syntax : <INPUT Perl distribution; these are called standard library
TYPE="HIDDEN" -NAME=" name" -VALUE=" modules and don’t have to be installed.
value" > We’re not doing use CGI.pm but rather use CGI. The
5) INPUT TYPE=”SUBMIT”: When a user clicks a .pm is implied in the use statement.
submit button, the form is submitted, The qw(:standard) part of this line indicates that we are
which means that the ACTION specified for the form is importing the “standard” set of function from CGI.pm.
invoked. Syntax: <INPUT TYPE #!/usr/bin/perl –wT -use CGI qw(:standard);-print
="SUBMIT" -NAME=" name" -VALUE=" value" > header;-print start_html(“Hello World”);-print
6) INPUT TYPE=”PASSWORD”: A password “<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
element is a text input field in which each webserver? Explain.
character typed is displayed as a character such as * or Ans: The Web server is software. It is responsible for
a black dot to conceal the actual value. accepting browser requests,
retrieving the specified file, and returning its contents. Q42. Explain any three method of the
Web servers first retrieve the javax.servlet.http.HttpSession interface.
request using Berkeley sockets. The Web server listens Ans. a) void addCookie(Cookie cookie): -Adds the
for requests on a particular specified cookie to the response object
port on the server machine. Once the b) java.util.Enumeration getAttributeNames():
server receives the request, it locates the -Returns Java Enumeration of String objects containing
document being requested. It looks for the the names of all the objects in this session.
file under the document root directory. c) long getCreationTime(): -Returns the time when
The server sends the contents of the file this session was created (measured in
back to the client. By default web browsers milliseconds since midnight January 1, 1970 GMT).
use port no. 80 for their requests. Once the d) long getLastAccessedTime(): -Returns the last time
server receives the request, it locates the the client sent a request in
document being requested. It looks for the with this session, as the number of milliseconds since
file under the document root directory. For example, if midnight January 1, 1970 GMT.
the document root is /usr/local/httpd/htdocs, e) int getMaxInactiveInterval(): - Returns the
and the client requests the document maximum time, in seconds, which the
/staff/matthew.html, then the server retrieves server will keep this session open between client
/usr/local/httpd/ accesses.
htdocs/staff/ matthew.html.The server sends the f) void removeAttribute(java.lang.String name):
contents of the file back to the client, along with some -Removes the object with
HTTP response headers. Among the data in the the specified name from this session.
response headers is the media type (also known as a
content type or MIME type), i.e., the format that the file Q43. What do you mean by scriptlets in JSP?
is in. Ans: Scriptlets are the JSP components that bring all
the JSP elements together.
Q41.Explain JSP error handling. They can contain almost any coding statements that are
Ans: Like all development methods, JSPs need a valid for the language
dynamic mechanism for handling errors. referenced in the language directive. They are executed
The JSP architecture provides an error-handling at request time, and they
solution through the use of JSPs that are can make use of all the JSP components. The syntax
written exclusively to handle JSP errors. The errors that for a scriptlet is as follows:
occur most frequently are runtime <% scriptlet source %>
errors that can arise either in the body of the JSP page
or in some other object that is called Q44.What is SSL? What is the necessity of it?
from the body of the JSP page. Request-time errors that Explain the working of SSL.
result in an exception being thrown Ans: SSL stands
can be caught and handled in the body of the calling for
JSP, which signals the end of the error. Secure Sockets
Exceptions that are not handled in the calling JSP result Layer.
in the forwarding of the client request, SSL is a protocol.
including the uncaught exception, to an error page It is developed by
specified by the offending JSP. Here we Netscape, has become the
see how an error page works, let’s create a simple JSP universal standard on the
that throws an uncaught exception. Web for authenticating
The JSP shown here uses the error page created in the Web sites to Web browser
previous section. users, and for encrypting
<%@ page errorPage=”errorpage.jsp” %><%if ( true ) communications between browser users and Web
{ throw new Exception(“An uncaught servers. The main role of SSL
Exception”);}%> In this listing that the first line of is to provide security for Web traffic. Security includes
code sets errorPage equal to errorpage.jsp, onfidentiality, message
which is the name of the error page. To make a JSP integrity, and authentication. The working of SSL is:
aware of an error page,we simply need to add the SSL has two distinct entities,
errorPage attribute to the page directive and set its server and client. The client is the entity that initiates
value equal to the location of our JSP error page. the transaction, whereas the
server is the entity that responds to the client and ID="namedPlaceOrStyle" –LANG=”ISO”
negotiates which cipher suites -STYLE=”style” > </OL>.
are used for encryption. In SSL, the Web browser is Unordered list: The UL tag displays a bulleted list.
the client and the Web-site You can use the tag’s TYPE
server is the server. Three protocols lie within SSL, the attribute to change the bullet style. Use the LI tag to
Handshake Protocol, designate the individual list items in the list.
the Record Protocol, and the Alert Protocol. The client Syntax: <UL TYPE="CIRCLE"|"DISC"|"SQUARE"
authenticates the server -CLASS="styleClass" –
during the Handshake Protocol. When the session is ID="namedPlaceOrStyle"—LANG= “ISO”
initiated and the handshake -STYLE=”style” > </UL>.
is complete, the data transfer is encrypted during the
Record Protocol phase. Q48.Write HTML script to display “Hello world,
If there are any alarms at any point during the session, welcome to the
the alert is attached to world of HTML”, the title as “world of HTML”.
the questionable packet and handled according to the Ans: <HTML><HEAD><TITLE>world of
Alert Protocol. HTML</TITLE><Script language=”Java Script”>
Hello world, welcome to the world of
Q45. Write a JavaScript program to pop up an alert HTML</SCRIPT></HEAD><BODY></BODY>
message. </HTML>
Ans: <HTML> <HEAD> <Script language=”Java
Script”> alert (“This is an alert message for java Q49.Write a JSP program which displays different
script”) message to the user based on the time of day.
</SCRIPT></HEAD><BODY></BODY></HTML> Ans: <%@ taglib prefix=”c”
uri=”http://java.sun.com/jstl/core” %> <html> <body
Q46.Explain in brief how to use hidden controls in a bgcolor=”white”>
web page. Give an example. Further, <jsp:useBean id=”clock” class=”java.util.Date” />
list the advantages and disadvantages of hidden <c:choose><c:when test=”${clock.hours < 12}”>
controls. <h1>Good morning!</h1></c:when><c:when test=”$
Ans: Using HTML hidden control is an easy way to {clock.hours < 18}”><h1>Good day!</h1>
store data in a webpage. </c:when><c:otherwise><h1>Good evening!
The user set the text to store in a hidden control in a </h1></c:otherwise></c:choose>Welcome to our site,
text field. open 24 hours a day.</body></html>.
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 Q50.With diagram explain the life-cycle of Servlet in
some information with the user that’s not directly briefly.
accessible to him. Hidden Ans: The lifecycle of a Servlet consists of the following
controls to store data in the Web page sent to the fundamental stages:
browser and then sent back to the server • Instantiation - The web server creates an
Disadvantages: Storing data in hidden controls is not instance of a servlet. This based on a request or
very secure. The data stored in those a container startup
controls is visible if the user views the page’s HTML • Initialization - The web server creates the
source. We can’t store data between sessions. instance’s init() method. When web server loads
a web application, it also loads the initialization
Q47.Explain the ordered lists and unordered lists. parameters associated with the application.
Ans: Ordered lists: The OL tag displays an ordered, • Service - This is the third state in the servlet
or numbered, list. The default numbering lifecycle. In this state the servlets service()
style is determined by the browser, but you can use the method is called which generates response.
tag’s TYPE attributes to change the i) Setting the content type of the
numbering sequence and numbering style. Use the LI response. The receiving application
tag to designate the individual list items. (browser) uses this information to
Syntax: <OL -START="value"- TYPE= "A" |"a"| "I" know how to treat the response data.
|"I "|"1" -CLASS= "styleClass” –
ii) Print Writer is a class from java.io caption for the table. We can use the CELLSPACING
package that extends the attribute to specify
java.io.writer abstract class. the distance between cells in the table and the
iii) We can use meta tags in the HTML CELLPADDING attribute to
generated to indicate browser not to specify the distance between the border and content of
cache page and some of the similar every cell.
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

Você também pode gostar