You are on page 1of 18

UNIT-III

PART – A

1.What is the DOM?

DOM is a platform independent, World Wide Web Consortium (W3C) standard


form of representation of structured documents as an object-oriented model. It is an
application programming interface so as to access HTML and XML documents.

2.What is the HTML DOM?

The HTML DOM API specializes and adds the functionality to relate to HTML
documents and elements. It addresses the issues of backwards compatibility with the
Level 0 of DOM and provides mechanisms for common and frequent operations on
HTML documents.

3.Explain the difference between DOM and SAX.

DOM

DOM is an interface-oriented Application Programming Interface. It allows for


navigation of the entire document. A DOM document can be created by a parser, or can
be generated manually by users. Data types in DOM Nodes are abstract. DOM
implementations generally require the entire document to be loaded into memory and
constructed as a tree of objects before access is allowed. DOM is supported in Java. Its
specification is regulated by the World Wide Web Consortium.

SAX

SAX parser works incrementally and generates events that are passed to the
application. DOM parser reads the whole XML document and returns a DOM tree
representation of xml document

In DOM the xml file is arranged as a tree and backward and forward search is possible In
SAX traversing in any direction is not possible as Top to bottom approach is used.

SAX is essentially an API for reading XML, and not writing it. DOM allows you to read
and write.
4.Explain the features of DOM.

DOM is Document Object Model. It is used to read data from a XML


document. It is more commonly used in applications where data in the document needs to
be repeated accessed. DOM supports navigation in any direction. XML DOM is typically
used for XML documents. The DOM defines the objects and properties of all document
elements, and the methods (interface) to access them.

5.What is the XMLHttpRequest Object?

The XMLHttpRequest object is used to connect to the server through http.


Scripts use it to do so programmatically.

The EventTarget interface needs to be implemented if an object implements the


XMLHttpRequest interface. Also, an XMLHttpRequest() constructor needs to be
provided by objects that implement the Window interface

6.What is XSL-FO?.

XSL-FO stands for Extensible Stylesheet Language Formatting Objects. It is used to


format XML data and is also a W3C recommendation.

7.Explain common XMLHttpRequest Object Properties ?

• The ‘onreadystatechange’ property fires at every state change event.


• The ‘readyState’ property is an object status integer. It uses the integers 0 to 4 for
uninitialized, loading, loaded, interactive and complete states.
• The ‘responseText’ property is a string version of data returned from server
process.
• The ‘responseXML’ property is DOM-compatible document object of data
returned from server process.
• The ‘status’ property is for returning numeric codes from the server like error
codes, etc.
• The ‘statusText’ property is used for string messages that accompany the status
code.
8.What are the properties and methods of HTML DOM?

Properties and methods are help us to define HTML DOM programming interface.
some properties of HTML DOM are given. Let, 'e' is an HTML element or node object.
• e.innerHTML : It shows the inner text value of e.
• e.nodeName : It shows the name of e.
• e.nodeValue : It shows the value of e.
• e.parentNode: It shows the parent node of e.
• e.childNodes: It shows the child node of e.
• e.attributes: It shows the attribute nodes of e.

some methods that we used in HTML DOM.


• e.getElementById(id) : Using them we can get the element with a specified id in
an HTML document.
• e.getElementsByTagName(name) : Using them we can get all elements with a
specified tag name in an HTML document.
• e.appendChild(node) : Using them we can insert a child node to e or increase the
no of child nodes of e.
• e.removeChild(node) : Using them we can remove a child node from e in an
HTML DOM

9.How you define events in HTML DOM?

Generally, Events are nothing other than actions. Using JavaScript we can
noticed or triggered events.Exampe: When you use click on button than an event occur
and function associated with button execute.We palced events within HTML tags.

10.How to change the background color of an element?

I have given you a script code using them you can change the background
color of elements of body.
<html>
<body>
<script type="text/javascript">
document.body.bgColor="pink";
</script>
<p>Now, Your background color is pink.</p>
</body>

</html>

11.How to change the text of an element?

I have given you a scipt code using them you can change the text of an HTML
element.Now, In example that I have shown below we change the text of the element
<p>.

Example:
<html>
<body>
<p id="welcome">R4R Welcomes You!</p>
<script type="text/javascript">
document.getElementById("welcome").innerHTML="A new message from R4R";
</script>
<p>R4R introduce a new service called VoiceBox using them you can chat with
R4R.</p>
</body>

</html>

12.Using function how to change the background color?

I have given you example which shows you how to change background color
by using function.

<html><head><script type=\"text/javascript\">function ChangeBackground()


{document.body.style.backgroundColor=\"pink\";}</script></head><body><p
id=\"welcome\">R4R Welcomes You!</p><input type=\"button\"
onclick=\"ChangeBackground()\"value=\"When you click on button than background
color will changed.\"></body></html>

13.How to changed font and color of an text element?


I have given you example using them you can change font and text of an
element by using a function.
Example:
<html>
<head>
<script type="text/javascript">
function ChangeText()
{
document.getElementById("welcome").style.color="red";
document.getElementById("welcome").style.fontFamily="Times New Roman";
document.getElementById("welcome").style.fontSize="20";
}
</script>
</head>
<body>
<p id="welcome">R4R Welcomes You!</p>
<input type="button" onclick="ChangeText()"
value="When you click on button text font and color will change">
</body>
</html>

14.What is an XML namespace name?

An XML namespace name is a URI that uniquely identifies the namespace.


URIs are used because they are widely understood and well documented.
Because people may only allocate URIs under their control, it is
easy to ensure that no two XML namespaces are identified by the
same URI.

15.Difference between GET and POST Method ?

When the user enters information in a form and clicks Submit , there are two
ways the information can be sent from browser to server: in the URL, or within the body
of the HTTP request.

The GET method, which was used in example earlier, appends name/value
pairs to the URL. Unfortunately, the length of URL is limited, so this method only works
if there are only a few parameters. The URL could be truncated if the form uses a large
number of parameter or if the parameters contain large amounts of data. Also, parameters
passed on URL are visible in the address field of the browsernot the best place for a
password to be displayed.

The alternative to the GET method is POST method. This method packages
the name/value pairs inside the body of HTTP request, which makes for a cleaner URL
and imposes no size limitation on the forms output. It is more secure.

16.Explain the life cycle methods of a Servlet.

The javax.servlet.Servlet interface defines the three methods known as life-cycle


method.
public void init(ServletConfig config) throws ServletException
public void service( ServletRequest req, ServletResponse res) throws
ServletException, IOException
public void destroy()
First the servlet is constructed, then initialized wih the init() method.
Any request from client are handled initially by the service() method before delegating to
the doXxx() methods in the case of HttpServlet.

The servlet is removed from service, destroyed with the destroy() methid, then garbaged
collected and finalized.

17.Explain the directory structure of a web application?

The directory structure of a web application consists of two parts.

• A private directory called WEB-INF


• A public resource directory which contains public resource folder.

WEB-INF folder consists of


1. web.xml
2. classes directory
3. lib directory

18.What are the common mechanisms used for session tracking?

• Cookies
• SSL sessions
• URL- rewriting

19.Explain ServletContext.

ServletContext interface is a window for a servlet to view it's environment. A


servlet can use this interface to get information such as initialization parameters for the
web applicationor servlet container's version. Every web application has one and only
one ServletContext and is accessible to all active resource of that application.

20.What is the difference between Difference between doGet() and doPost()?

A doGet() method is limited with 2k of data to be sent, and doPost() method


doesn't have this limitation. A request string for doGet() looks like the following:
http://www.allapplabs.com/svt1?p1=v1&p2=v2&...&pN=vN
doPost() method call doesn't need a long text tail after a servlet name in a request. All
parameters are stored in a request itself, not in a request string, and it's impossible to
guess the data transmitted to a servlet only looking at a request string.

21.What is the difference between HttpServlet and GenericServlet?

A GenericServlet has a service() method aimed to handle requests.


HttpServlet extends GenericServlet and adds support for doGet(), doPost(), doHead()
methods (HTTP 1.0) plus doPut(), doOptions(), doDelete(), doTrace() methods (HTTP
1.1). Both these classes are abstract.

22.What is the difference between ServletContext and ServletConfig?

ServletContext: Defines a set of methods that a servlet uses to communicate with its
servlet container, for example, to get the MIME type of a file, dispatch requests, or write
to a log file.The ServletContext object is contained within the ServletConfig object,
which the Web server provides the servlet when the servlet is initialized

ServletConfig: The object created after a servlet is instantiated and its default constructor
is read. It is created to pass initialization information to the servlet.
23.What is Servlet?

A servlet is a Java technology-based Web component, managed by a container


called servlet container or servlet engine, that generates dynamic content and interacts
with web clients via a request\/response paradigm.

24.Why is Servlet so popular?

Because servlets are platform-independent Java classes that are compiled to


platform-neutral byte code that can be loaded dynamically into and run by a Java
technology-enabled Web server.

25.What is servlet container?

The servlet container is a part of a Web server or application server that


provides the network services over which requests and responses are sent, decodes
MIME-based requests, and formats MIME-based responses. A servlet container also
contains and manages servlets through their lifecycle.

26.When a client request is sent to the servlet container, how does the container
choose which servlet to invoke?

The servlet container determines which servlet to invoke based on the


configuration of its servlets, and calls it with objects representing the request and
response.

27.If a servlet is not properly initialized, what exception may be thrown?

During initialization or service of a request, the servlet instance can throw


an UnavailableException or a ServletException.
28.Given the request path below, which are context path, servlet path and path
info?

/bookstore/education/index.html

context path: /bookstore


servlet path: /education
path info: /index.html

29.What is filter? Can filter be used as request or response?

A filter is a reusable piece of code that can transform the content of


HTTP requests,responses, and header information. Filters do not generally create a
response or respond to a request as servlets do, rather they modify or adapt the requests
for a resource, and modify or adapt responses from a resource.

30.When using servlets to build the HTML, you build a DOCTYPE line, why do you
do that?

I know all major browsers ignore it even though the HTML 3.2 and 4.0
specifications require it. But building a DOCTYPE line tells HTML validators which
version of HTML you are using so they know which specification to check your
document against. These validators are valuable debugging services, helping you catch
HTML syntax errors.

31.What is new in ServletRequest interface ? (Servlet 2.4)


The following methods have been added to ServletRequest 2.4 version:

• public int getRemotePort()


• public java.lang.String getLocalName()
• public java.lang.String getLocalAddr()
• public int getLocalPort()
32.How to find whether a parameter exists in the request object?

• boolean hasFoo = !(request.getParameter("foo") == null ||


request.getParameter("foo").equals(""))
• boolean hasParameter = request.getParameterMap().contains(theParameter);
(which works in Servlet 2.3+)

33.How can I send user authentication information while making URL Connection?

You'll want to use HttpURLConnection.setRequestProperty and set all the


appropriate headers to HTTP authorization.

34.Can we use the constructor, instead of init(), to initialize servlet?

Yes , of course you can use the constructor instead of init(). There's nothing to
stop you. But you shouldn't. The original reason for init() was that ancient versions of
Java couldn't dynamically invoke constructors with arguments, so there was no way to
give the constructur a ServletConfig. That no longer applies, but servlet containers still
will only call your no-arg constructor. So you won't have access to a ServletConfig or
ServletContext.

35.What mechanisms are used by a Servlet Container to maintain session


information?

Cookies, URL rewriting, and HTTPS protocol information are used to


maintain session information

36.Difference between GET and POST ?

In GET your entire form submission can be encapsulated in one URL, like a
hyperlink. query length is limited to 260 characters, not secure, faster, quick and easy.
In POST Your name/value pairs inside the body of the HTTP request, which makes for a
cleaner URL and imposes no size limitations on the form's output. It is used to send a
chunk of data to the server to be processed, more versatile, most secure.

37.What is session?

The session is an object used by a servlet to track a user's interaction with a


Web application across multiple HTTP requests.

38.What is servlet mapping?

The servlet mapping defines an association between a URL pattern and a


servlet. The mapping is used to map requests to servlets.

39.What is servlet context ?

The servlet context is an object that contains a servlet's view of the Web
application within which the servlet is running. Using the context, a servlet can log
events, obtain URL references to resources, and set and store attributes that other servlets
in the context can use. (answer supplied by Sun's tutorial).

40.Which interface must be implemented by all servlets?

Servlet interface.

41.Explain the life cycle of Servlet.

Loaded(by the container for first request or on start up if config file suggests
load-on-startup), initialized( using init()), service(service() or doGet() or doPost()..),
destroy(destroy()) and unloaded.
42.When is the servlet instance created in the life cycle of servlet? What is the
importance of configuring a servlet?

An instance of servlet is created when the servlet is loaded for the first time in
the container. Init() method is used to configure this servlet instance. This method is
called only once in the life time of a servlet, hence it makes sense to write all those
configuration details about a servlet which are required for the whole life of a servlet in
this method.

43.Why don't we write a constructor in a servlet?

Container writes a no argument constructor for our servlet.

44.When we don't write any constructor for the servlet, how does container create
an instance of servlet?

Container creates instance of servlet by calling Class.forName(className).newInstance()

45.Once the destroy() method is called by the container, will the servlet be
immediately destroyed? What happens to the tasks(threads) that the servlet might
be executing at that time?

Yes, but Before calling the destroy() method, the servlet container waits for the
remaining threads that are executing the servlet’s service() method to finish.

46.What is the difference between callling a RequestDispatcher using


ServletRequest and ServletContext?

We can give relative URL when we use ServletRequest and not while
using ServletContext.
47.Why is it that we can't give relative URL's when using
ServletContext.getRequestDispatcher() when we can use the same while calling
ServletRequest.getRequestDispatcher()?

Since ServletRequest has the current request path to evaluae the relative
path while ServletContext does not.

48.List any two keyboard events?

• onKeypress
• onKeyUp
• onKeyDown

49. List any two mouse events?

• onMouseUp
• onMouseDown
• onMouseOver
• onClick

50.Difference between Servlets and Applets?

Servlet:

• A small program that runs on a server, the term usually refers to a Java
applet that runswithin a Web server environment. This is analogous to a
Java applet that runs within a Webbrowser environment.
• Java servlets are becoming increasingly popular as an alternative to CGI
programs.
• Thebiggest difference between the two is that a Java applet is persistent.
This means that once it is started, it stays in memory and can fulfill multiple
requests.
• In contrast, a CGI program disappears once it has fulfilled a request. The
persistence of Java applets makes them faster because there\'s no wasted
time in setting up and tearing down the process.

Applet

• A program designed to be executed from within another application. Unlike


anapplication, applets cannot be executed directly from the operating system. With
the growingpopularity of OLE (object linking and embedding), applets are
becoming more prevalent.
• A well-designed applet can be invoked from many different applications.
• Web browsers, who are often equipped with Java virtual machines, can interpret
appletsfrom Web servers. Because applets are small in files size, cross-platform
compatible, andhighly secure (can’t be used to access users\' hard drives), they are
ideal for small Internet applications accessible from a browser.

51. What do you mean by Server-side?

Occurring on the server side of a client-server system. For example, on the World
Wide Web, CGI scripts are server-side applications because they run on the Web server.
In contrast, JavaScript scripts are client-side because they are executed by your browser
(the client). Java applets can be either server-side or client- side depending on which
computer (the server or the client) executes them.

52.What is the difference between the getRequestDispatcher(String path) method of


javax.servlet.ServletRequest interface and javax.servlet.ServletContext interface?

The getRequestDispatcher(String path) method of javax.servlet.ServletRequest


interface accepts parameter the path to the resource to be included or forwarded to, which
can be relative to the request of the calling servlet. If the path begins with a \"/\" it is
interpreted as relative to the current context root.

The getRequestDispatcher(String path) method of javax.servlet.ServletContext interface


cannot accepts relative paths. All path must sart with a \"/\" and are interpreted as relative
to curent context root.
53. Explain about Session tracking?

• A session is basically a conversation between a browser and a server. All the


above technologies can save information for the current session for a particular
user visiting a site.
• The session is important, as H1TP is a stateless protocol. This means that the
connection between web server and a web browser is not automatically
maintained, and that the state of a web session is not saved.
• State is a general term that includes \"everything about your situation\" and the
specifics vary based on the application. In a word processor, the state of the
application would include which windows are open, where they are on the screen,
and what files you most recently used.
• In a web application, the state would include any data that you had entered, the
results of any queries that you had run, and your security access information (e.g.
whether you have logged in to the site).

54. What is preinitialization of a servlet?

A container doesnot initialize the servlets ass soon as it starts up, it initializes
a servlet when it receives a request for that servlet first time. This is called lazy loading.
The servlet specification defines the <load-on-startup> element, which can be specified in
the deployment descriptor to make the servlet container load and initialize the servlet as
soon as it starts up. The process of loading a servlet before any request comes in is called
preloading or preinitializing a servlet.

55. What is the difference between HttpServlet and GenericServlet?

A GenericServlet has a service() method aimed to handle requests.


HttpServlet extends GenericServlet and adds support for doGet(), doPost(), doHead()
methods (HTTP 1.0) plus doPut(), doOptions(), doDelete(), doTrace() methods (HTTP
1.1).

Both these classes are abstract.

PART B
1. Explain the concept of Servlets with an example program

2. Explain about applet to servlet communication with example program?

3. Explain about applet-to-applet communication with example program?

4. Explain about servlet interfaces with snippet code?

5. What are attributes are available for servlet and explain each of them

6. What do mean by Connection pooling? Explain it with an example.

7. What is HTTP Tunneling? Explain with an example

8. What\'s the difference between sendRedirect( ) and forward( ) methods? Explain each
with an example

9. List down the methods of GenericServlet .Explain ach of them with an example

10. List down the methods of HttpServlet .Explain ach of them with an example

List down the methods of SevletConfig .Explain ach of them with an example

11. List down the methods of Servletcontext .Explain ach of them with an example

12. Explain implicit objects with example

13. Explain about JSP expressions

14. Explain about JSP actions with example

15. Write down the differences between <jsp: include> and <@include…> with example

16. Briefly explain about Java Server Pages technology

17. Why do I need JSP technology if I already have servlets? And explain the features of
JSP over servlet.

18. Explain how are the JSP requests handled with an example?

19. What are Directives? Explain about JSP diecives.


20. Explain in details about taglib .

21. Explain the concepts of JSP directives with suitable example.

22. Explain THE various session tracking MECHANISMS.

23. Explain the architechture of a Servlet?

24. Explain life cycle of a Servlet?

25. What is Servlet Chaining? Explain with an example

26. Explain the concepts of Servlet chaining and communications.

27. Explain about session tracking.

28. Two ways of maintaining the sessions:

i. Cookies

ii. Rewriting URLs

29. Example for session tracking, Shopping cart

30. Explain the feature of Multi-tier application using servlet architecture.

31. Explain the Servlet architecture with its functionality.

32. Develop an HTML document to generate ballot form for an election. The votes
submitted are recorded on the server by a servlet handling the form. Cookies must be
used to prevent multiple votes by the same client.

33. What is DOM? Explain its usage with HTML with an example.

34. Write a servlet program to implement session tracking using HTTP session object.

35. Compare JSP with servlets.

36. Discuss the traditional methods of session tracking techniques in servlet explain with
example.
37. Explain DOM. Write a Javascript Program to validate Radio Button,CHECKBOX
and OPTION fields.

38. Explain the servlet life cycle model and explain javax.servlet package

39. Write a HTTP servlet program to authenticate a user and retrieve all information from
a HTML registration Form and store in a given data base.

40. Explain the various Java Script objects & Host objects

41. What is DOM? Draw the detailed DOM objects structure. Explain with its usage.

You might also like