5)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. The session is stored on the server.
6)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.
7)What
is servlet context
The
servlet context is an object that contains a information about the Web
application and container. 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.
8)What
is a servlet?
servlet
is a java program that runs inside a web container.
9)Can
we use the constructor, instead of init(), to initialize servlet?
Yes.
But you will not get the servlet specific things from constructor. 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 constructor 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.
10)How
many JSP scripting elements are there and what are they?
There are three scripting language elements:
declarations, scriptlets, expressions.
11)How
can I implement a thread-safe JSP page?
You
can make your JSPs thread-safe adding the directive <%@ page
isThreadSafe="false" % > within your JSP page.
12)What
is the difference in using request.getRequestDispatcher() and
context.getRequestDispatcher()?
In
request.getRequestDispatcher(path) in order to create it we need to give the
relative path of the resource. But in
resourcecontext.getRequestDispatcher(path) in order to create it we need to
give the absolute path of the resource.
13)What
are the lifecycle of JSP?
When
presented with JSP page the JSP engine does the following 7 phases.
Page translation: -page is parsed, and a java
file which is a servlet is created.
Page
compilation: page is compiled into a class file
Page
loading : This class file is loaded.
Create
an instance :- Instance of servlet is created
jspInit()
method is called
_jspService
is called to handle service calls
_jspDestroy
is called to destroy it when the servlet is not required.
14)What
are context initialization parameters?
Context
initialization parameters are specified by the <context-param> in the
web.xml file, these are initialization parameter for the whole application.
15)What
is a Expression?
Expressions
are act as place holders for language expression, expression is evaluated each
time the page is accessed. This will be included in the service method of the
generated servlet
16)What
is a Declaration?
It declares one or more variables or methods
for use later in the JSP source file. A declaration must contain at least one
complete declarative statement. You can declare any number of variables or
methods within one declaration tag, as long as semicolons separate them. The
declaration must be valid in the scripting language used in the JSP file. This
will be included in the declaration section of the generated servlet.
17)How do I include static files within a JSP page?
Static resources should always be included using the JSP include directive. This way, the inclusion is performed just once during the translation phase.
0 comments:
Post a Comment