|
21 |
Q |
What are the implicit objects? |
|
|
A |
Certain objects that are available for the
use in JSP documents without being declared first. These objects
are parsed by the JSP engine and inserted into the generated
servlet. The implicit objects are: request, response,
pageContext, session, application, out, config, page, exception |
|
|
|
|
|
22 |
Q |
What's the difference between forward and
sendRedirect? |
|
|
A |
forward is server side redirect
and sendRedirect is client side redirect. When you invoke a
forward request, the request is sent to another resource on the
server, without the client being informed that a different
resource is going to process the request. This process occurs
completely with in the web container And then returns to the
calling method. When a sendRedirect method is invoked, it causes
the web container to return to the browser indicating that a new
URL should be requested. Because the browser issues a completely
new request any object that are stored as request attributes
before the redirect occurs will be lost. This extra round trip a
redirect is slower than forward. Client can disable sendRedirect. |
|
|
|
|
|
23 |
Q |
What are the different scopes available ? |
|
|
A |
page, request, session, application |
|
|
|
|
|
24 |
Q |
Is JSP extensible ? |
|
|
A |
Yes, it is. JSP technology is extensible
through the development of custom actions, or tags, which are
encapsulated in tag libraries. |
|
|
|
|
|
25 |
Q |
What's the Servlet Interface? |
|
|
A |
The central abstraction in the Servlet API
is the Servlet interface. All servlets implement this interface,
either directly or, more commonly, by extending a class that
implements it such as HttpServlet. |
|
|
|
|
|
26 |
Q |
What are two different types of Servlets ? |
|
|
A |
GenericServlet and HttpServlet.
HttpServlet is used to implement HTTP protocol, where as Generic
servlet can implement any protocol. |
|
|
|
|
|
27 |
Q |
What is the life cycle of servlet? |
|
|
A |
Each servlet has the same life cycle:
first, the server loads and initializes the servlet by calling
the init method. This init() method will be executed only once
during the life time of a servlet. Then when a client makes a
request, it executes the service method. finally it executes the
destroy() method when server removes the servlet. |
|
|
|
|
|
28 |
Q |
Can we call destroy() method on servlets from
service method ? |
|
|
A |
Yes. |
|
|
|
|
|
29 |
Q |
What is the need of super.init (config) in
servlets ? |
|
|
A |
Then only we will be able to access the
ServletConfig from our servlet. If there is no ServletConfig our
servlet will not have any servlet nature. |
|
|
|
|
|
30 |
Q |
What is the difference between GenericServlet
and HttpServlet? |
|
|
A |
GenericServlet supports any protocol.
HttpServlet supports only HTTP protocol. By extending
GenericServlet we can write a servlet that supports our own
custom protocol or any other protocol. |
|
|
|
|
|
32 |
Q |
Can we write a constructor for servlet ? |
|
|
A |
Yes. But the container will always call
the default constructor only. If default constructor is not
present , the container will throw an exception. |
|
|
|
|
|
33 |
Q |
What is the difference between <%@ include
...> (directive include) and <jsp:include> ? |
|
|
A |
@ include is static include. It is inline
inclusion. The contents of the file will get included on
Translation phase. It is something like inline inclusion. We cannot have a dynamic filename for
directive
include. <jsp:include> is dynamic include. Here the included
file will be processed as a separate file and the response will
be included. We can have a dynamic filename for <jsp:include>.
We can aslo pass parameters to <jsp:include |
|
|
|
|
|
34 |
Q |
Can I just abort processing a JSP? |
|
|
A |
Yes. You can put a return statement to
abort JSP processing. |
|
|
|
|
|
35 |
Q |
What are the parameters for service method ? |
|
|
A |
ServletRequest and ServletResponse |
|
|
|
|
|
36 |
Q |
What are cookies ? |
|
|
A |
Cookies are small textual information that are stored on client computer. Cookies are used for session tracking.
|
|
|
|
|
|
37 |
Q |
How do I prevent the output of my JSP or
Servlet pages from being cached by the browser? |
|
|
A |
By setting appropriate HTTP header attributes
we can prevent caching by the browser
<% response.setHeader("Cache-Control","no-store"); //HTTP 1.1 response.setHeader("Pragma","no-cache"); //HTTP 1.0 response.setDateHeader ("Expires", 0); //prevents caching at the proxy server %> |
|
|
|
|
|
38 |
Q |
How to refer the "this" variable within a JSP
page? |
|
|
A |
Under JSP 1.0, the page implicit object page
is equivalent to "this", and returns a reference to the servlet
generated by the JSP page. |
|
|
|
|
|
39 |
Q |
How many JSP scripting elements and what are
they? |
|
|
A |
There are three scripting elements in
JSP . They are declarations, scriptlets, expressions. |
|
|
|
|
|
40 |
Q |
Can we implement an interface in JSP ? |
|
|
A |
No. |