| |
Struts Tutorials:
Struts2 Tag CheckBoxList , Checkbox, Iterator, IF
Struts2 Tag Library Example
Struts2 Tiles Example
Struts2 Tiles I18N Example
Struts2 Questions
Struts Tiles I18N Example
Struts Eclipse MVC
Struts2 Tags
Struts2 Example and Tutorial
Struts MVC
Struts2 Validation
Hibernate Tutorials:
Hibernate Case Study
Class Hierarchy Persist Example
Using Hibernate Interceptor
Hibernate Questions with Answer
Hibernate Many-to-Many Mapping Example
Hibernate one-to-many Mapping Example
Hibernate and ORM tools
Spring Hibernate Example
Hibernate SessionFactory Example
Hibernate Mapping Class Hierarchy
Hibernate Questions
Hibernate SessionFactory Questions
Spring Hibernate Example:
Spring Hibernate Case Study
Written By : Amit
Title :
Tag Library
Description :
Demo code required More...
|
Written By : Amit
Title :
Interview Questions answer
Description :
Add Your Questions on Servlet and JSP More...
|
Written By : Amit
Title :
JSF Example
Description :
Simple Tutorial More...
|
Written By : Amit
Title :
JSF Validation
Description :
Simple Tutorial More...
|
Written By : Amit
Title :
JSF Tag
Description :
Simple Tutorial More...
|
| Tags/Keywords : Servlet interview questions, Servlet Questions, answer, question, servlet Author : Amit Date (Year/Month/Date): 2009-07-08
Servlet Interview Questions with my answer listed as follows | | Servlet Question 1. Can a Java Thread be started
from Servlet class, and what will be
the implications?
Servlet Answer :
Yes, it is possible to write a Thread or
start a Thread from Servlet. In fact
a Servlet can be started on load of the
web application by defining
"load-on-startup" tag value as
"1" in the "web.xml"
file.
One should not start/create a thread from
a Servlet that is to be invoked by
browser or Java client application. Reason
is that web container has Threads
running to delegate every client request
to appropriate Servlet instance.
If servlet instance starts a thread from
every request, then it is like
each thread spanning multiple threads.
As HTTP is stateless protocol, and
after response is sent back to client,
job of servlet is over, and web container
manages the lifecycle of the servlets,
but not responsible for the lifecycle
or management of the Threads those
Servlets have created.
If need is to to some kind of scheduling
operation, then it is allows advisable
to try for some good Scheduler frameworks
available.
Servlet Question 2. What is HTTP Session tracking and why is it important?
Servlet Answer :
HTTP Session tracking is the way Web server knows that the request is not a
fresh or new request, and has a session already created in the web context.
So when a request reaches web server, it looks for a variable called
jsessionid, that should be associated with the request either in form of
cookies, or URL rewriting. If your site visitor has blocked all cookies
then redirect to another JSP or Servlet, will not be able to carry
the same session, and all the data/object reference stored in HttpSession
is/are lost. But is this redirect is done by using encodeURL method of
HttpServletResponse object, then session id is attached as a part of
URL and webserver attaches already created session to the new request.
Servlet Question 3. What is session management, and how is it different from session tracking?
Servlet Answer :
HTTP session management is related to the mechanism, by which application data
or client state can be passed from one request to another request
(As HTTP is stateless). Session Management is obviously comes after session
tracking, as without session tracking, client request cannot be hooked
onto one and only one session. But if requirement is to just pass reasonably
small data/variables, from one request to another, then it can be done,
by Hidden form field, and can be transported from browser to server, either
by POST or GET as method in HTML FORM tag.
Servlet Question 4. Can I use Hidden form field to track session?
Servlet Answer :
No, as Hidden form field sends its value as a request parameter, which is
not same as URL rewriting (passing jsessionid as part of URL).
Servlet Question 5. How can I pass method as request parameter to be called, instead of
default doGet or doPost method of HttpServlet object, on submit
of an URL?
Servlet Answer :
By overriding service method of HttpServlet object, and using reflection
to invoke the desired method of the servlet that is passed as a request
parameter. It is similar to the dispatcher mechanism implemented in Struts
framework for dynamic dispatching of action.
Servlet Question 6. In a architecture pattern like MVC, it is mandatory that Servlet should
be the controller, why not JSP?
Servlet Answer :
As JSP cannot be configured as a default mapping to be called based on a
URL pattern in web.xml file. In that case, not all request goes through
a JSP controller, and the very purpose of controller is not achieved.
As Servlet can be mapped to a particular URL in web.xml like,
<servlet-mapping>
<servlet-name>SampleController</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
Servlet Question 7. Why JSP is used as View part of MVC ?
Servlet Answer :
As JSP is easily configurable at runtime and by using Tag library,
XSL, and many more scripting language, productivity increases by
using JSP instead of Servlet.
Servlet Question 8. Can a database connection pool be instantiated in init method
of servlet instead of server connection pool? What will be the problem?
Servlet Answer :
It is true that connection pool can be instantiated in init method of Servlet
and is available for the web application to use, but generally there can be
many web application required to use database connection pool, and multiple
web applications do not have access beyond ServletContext.So it is desirable
to have external resources defined at server level, not at an application
level.
Servlet Question 9. How to implement Servlet singlethread model, by not using
singlethreadmodel?
Servlet Answer :
Please write your understanding on this Servlet Question.
|
| Are you interested in solving a very interesting Technology Stack while Playing this Game 
|
|
| Home >>> Servlet and JSP >>> Interview Questions answer >>> Add Your Questions on Servlet and JSP |
|
|
Visitor/User referred related external URL:
(Visible upon review and approved by this site Administrator)
|
|
|
|
|
<- requires login | Log in or Register | |
Copyright © 2008-2009, Interview-Questions-Tips-Forum, All Rights Reserved. | CONTACT PRIVACY POLICY DISCLAIMER |
 |
Terms of Use and Disclaimer :
This web site provides some of the information about various technologies, example
code, tips, tutorials etc. Like any printed materials, content of these pages may
become out of date over a period of time. Therefore all visitor/users of this web
site are requested/advised to refer to the originating parties/sources for the
latest changes and happenings for detailed information. This information is not
intended to be a substitute for the original reference provided by the originating
parties/sources.
By accessing and using this website in any ways, including, without
limitation, browsing the website pages, using any information, using any content and/or
downloading any materials, you agree to and are bound by the terms of use
described in this page and Usage Terms and Conditions.
If you do not agree to all of
the terms and conditions contained in the terms of use described in this
page and Usage Terms and Conditions, do not use this
website in any manner. If you are using the website on behalf of your
employer, you represent that you are authorized to accept these Terms of Use
on your employer's behalf.
All Trademarks are property of their respective owner. Appropriate measure is being
taken for providing accurate and up-to-date information but like any printed materials,
these blog(s)/contents may eventually be outdated one day, so if you are using any
of these information, please refer original content/documentation from respective sources.
And under no circumstances shall the Author of these contents and/or this web site
be liable for any loss, damage, expense incurred or suffered which is claimed to have
occurred because of usage of the contents of this web site.
If you have any questions/queries/feedback/suggestions then please write to this web
site owner at contact.
|  |
|
|
|
|
|