Professional Documents
Culture Documents
PART – A
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.
DOM
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.
6.What is XSL-FO?.
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.
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.
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>
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>
I have given you example which shows you how to change background color
by using function.
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.
The servlet is removed from service, destroyed with the destroy() methid, then garbaged
collected and finalized.
• Cookies
• SSL sessions
• URL- rewriting
19.Explain ServletContext.
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?
26.When a client request is sent to the servlet container, how does the container
choose which servlet to invoke?
/bookstore/education/index.html
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.
33.How can I send user authentication information while making URL Connection?
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.
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 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).
Servlet interface.
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.
44.When we don't write any constructor for the servlet, how does container create
an instance of servlet?
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.
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.
• onKeypress
• onKeyUp
• onKeyDown
• onMouseUp
• onMouseDown
• onMouseOver
• onClick
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
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.
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.
PART B
1. Explain the concept of Servlets with an example program
5. What are attributes are available for servlet and explain each of them
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
15. Write down the differences between <jsp: include> and <@include…> with example
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?
i. Cookies
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.
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.