ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage   interview questions urls   External Links  Contact Us     Login  |  Sign Up                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
Google
 
Categories >> Software >> Java-Related >> Java-J2EE >> Servlets
 
 


 

Back to Questions Page
 
Question
Is there any differance b/w getting servlet context from 
servlet config and session? if yes then what is that?
Rank Answer Posted By  
 Question Submitted By :: Vijay
I also faced this Question!!   © ALL Interview .com
Answer
servlet context:servletcontext is only one web web 
application object
servlet config: servlet config is multiple object in 
webapplication
 
0
Koti
 
 
Answer
Servlet config is one per servlet and servlet context is one for
the whole webapplication. 

Servlet config is used to pass deploy time information to servlet
where servlet context can be used to get information about the
container,server.
 
0
Nisha
 
 
Answer
YES,There is some difference,when we deploy the web 
application the web container will create the Context 
object and when we load the servlet class then container 
will create config object,so for each web application web 
container will create one servlet context obj and for each 
servlet web container will create servlet config object.

Generally we use this objects to avoid the hardcoding,we 
declare this variables in deployment descriptor,we declare 
context parameters under web-app tag so that all servlets 
can use this parameter values ,and config parameters under 
servlet tag so that only specific servlet can use this 
parameter values,in simple way context object is like 
global object and config obj is like local obj.
 
0
Sandhya
 
 
 
Question
what is the difference between do get/dopost
Rank Answer Posted By  
 Question Submitted By :: Guest
I also faced this Question!!   © ALL Interview .com
Answer
doGet is called in response to an HTTP GET request. This 
happens when users click on a link, or enter a URL into the 
browser's address bar. It also happens with some HTML FORMs 
(those with METHOD="GET" specified in the FORM tag). 
doPost is called in response to an HTTP POST request. This 
happens with some HTML FORMs (those with METHOD="POST" 
specified in the FORM tag). 

Both methods are called by the default (superclass) 
implementation of service in the HttpServlet base class. 
You should override one or both to perform your servlet's 
actions. You probably shouldn't override service().
 
0
Om Shastri
 
 
Answer
doGet method will append data to URL while transferring 
data to the server.

doPost method will not append data. It is considered to be 
secured. The data will be inside the body of request and 
response.
 
0
Kishore
 
 
Question
difference between forward and sendredirect
Rank Answer Posted By  
 Question Submitted By :: Vijayk
This Interview Question Asked @   Accenture
I also faced this Question!!   © ALL Interview .com
Answer
FORWARD-->
1. THE REQUEST AND RESPONSE OBJECT REMAIN SAME.
2. CONTROL DIRECTLY GOES TO REQUESTED PAGE AT THE POINT 
WHERE FORWARD IS CALLED.
3. REQUEST DISPATCHER IS NEEDED.

SEND REDIRECT:--->
1.NEW REQUEST AND RESPONSE IS GENERATED IN CASE THIS CASE.
2.IN THIS CASE FIRST CONTROL GOES TO CLIENT(BROWSER) AND 
THEN TO REQUESTED PAGE.
3.JUST RESPONSE OBJECT IS NEEDED.
 
0
Neeraj_passion2001
 
 
Answer
If I am not wrong,
forward() is used to transfer the request within the web 
application whereas sendRedirect() is used to transfer the 
request from one webapplication to another.
 
0
Uv
[Trycon Infotech]
 
 
Question
can it possible to validate form field before execution of a
servlet service method if yes how??
Rank Answer Posted By  
 Question Submitted By :: Rakesh Ray
I also faced this Question!!   © ALL Interview .com
Answer
yes, it is possible. write a javascript method to validate 
input fields and call this method based on event of your 
requirement.
 
0
Geetha
 
 
Answer
Yes,
If it client side validation do with the javascript
if it is serverside validation we can use Filters and do 
the validations there example login authenticated or not
 
3
Sekhar Babu
 
 
Answer
By using Filters u can also validating the form feilds
 
0
Alluri.nagaraju
 
 
Question
can we override service method in my servlet class..?? if 
yes or no why ??
Rank Answer Posted By  
 Question Submitted By :: Raj.polu
This Interview Question Asked @   IBM
I also faced this Question!!   © ALL Interview .com
Answer
yes, we can override service() in our servlet, but not 
preferable. if we want use these service from any protocol 
like ftp,telnet, then we have to override.
 
0
Sekhar Babu
 
 
Answer
we can override service method in my servlet class if the 
request is not protocol dependent.
Bcoz we exdend HttpSrevlet class to handle Http GET and 
POST requests and we have to override some methods like 
doGet,doPost,doHead,doPut,doDelete.

But if u want to override service method then u have to 
extend genricServlet Class.Then only u can implement Service
() method.
 
0
Ruchi
 
 
Question
Can we write a constructor for a Servlet class ? if yes how ?
if no why not ?
Rank Answer Posted By  
 Question Submitted By :: Suryakanth
I also faced this Question!!   © ALL Interview .com
Answer
you can write as like for regular class.
 
0
Abc
 
 
Answer
No..not at all,,,,servlet is a class which is dynamically 
loaded...dynamically loaded class never requires 
constructors.
 
0
Ravi
[SSoft]
 
 
Answer
constructor required, but it should be public no-argument
constructor. even though if you are not write that
constructor   java compiler will create that construtctor by
default. for that your servlet class should be public other
wise you will get RuntimeWxception saying RequestedResource
is not available  like that.
 
0
Chandra
[SSoft]
 
 
Answer
yes offcourse you can write a constructor for a servlet
after all it is a java class. you can simply provide but if
u do not provide then it is by default include the no
argument constructor that is used by the Init() method in
the servlet life cycle.
 
0
Abhishek Taneja
[SSoft]
 
 
Answer
yes, we can write constructor on our own but it should be 
no argument public constructor only, cause container will 
create the object so it needs no argument constructor.
 
0
Sekhar Babu
[SSoft]
 
 
Answer
yes., when ever the servlet is executed .,it requires 
configuration.,the configuration should be done in init() 
method only.,
 
0
N.l.narayana
[SSoft]
 
 
Question
If we disable cookies in our web page, what will happen?
Rank Answer Posted By  
 Question Submitted By :: Kalareddy
This Interview Question Asked @   Zensar
I also faced this Question!!   © ALL Interview .com
Answer
Cookies is used for identify to request.
if we disable the coookies then we cannot identify the 
request
 
2
Shailendra Sharma
 
 
Answer
If cookies are disabled in our browser, Session tracking 
gets failed.

To overcome this limitation URL Rewriting concept will be 
used.
 
3
Gajendra
 
 
Answer
to track web pages we can use

1. Cookies
2. URLRewriting
3. storing data in session
4. Using Hidden variable in form
 
0
Abc
 
 
Answer
if cookies are disable the session tracking gets failed it 
unable to identifies the clients previous request.

even cookies are disable we can maintain session with 
res.encodeURL("path") method.
 
0
Sekhar Babu
 
 
Answer
If we disable the cookies in our webpage then the it cant
identify the clients request.because there will be no
jsessionid  for our request.So it fails to remember our req
on the server .so once again it creates the sessionid for
another req.
 
0
Navatha
 
 
Question
What is a parser. What does a parser do with a XML? Why do 
we need it?
Rank Answer Posted By  
 Question Submitted By :: Shahidha
I also faced this Question!!   © ALL Interview .com
Answer
Parser is used to parser the xml file it parse the xml file
and set the data in the domain model and if the Schema
validation is set to true then it will validate the xml file
against the Schema .Parser is needed for reading the data
from the xml node and to populate that data
 
0
Sanjay Rawat
 
 
Question
can v create a constructor 4 servlet?
Rank Answer Posted By  
 Question Submitted By :: Guest
This Interview Question Asked @   Satyam
I also faced this Question!!   © ALL Interview .com
Answer
yes we can create constructor of servlet instead of init 
method but i dont get servlet specification answers.
 
0
Ravindra Nhavi
 
 
Answer
sure why not if we are not provide a constuctor for servlet 
it automatically get constructor by the java compiler if we 
provide a constuctor for a servlet the java compiler will 
not provide constuctor at that situation
 
0
Reddy Akhi
 
 
Answer
yes ofcourse we should.
it is mandatory for servlet.
for servlets we required publc no argument constructor. if v
don't having that one, our servlet should not work, even
though if you are not crating the public no-argument
constructor, the java compiler will take the responsibility
to create public no- argument constructor.. mean while your
servlet should be public otherwise you will get
RuntimeException.


we can create costructor for sevelet but it should b no-
argument constructor. and u r servlet should be public. 
and one more thing this constructor in not in the place of
init() method..
 
0
Chandra Kunchala
 
 
Question
What is the use of  RequestDispatcher in servlet?
Rank Answer Posted By  
 Question Submitted By :: Tathagata
I also faced this Question!!   © ALL Interview .com
Answer
RequestDispatcher is used to connect to another webresource
with in the same context.

RequestDispatcher
rd=ServletContext.getRequestDispatcher("url of resource");
rd.forward(req,res);----used to forward to another resource.
rd.include(req,res);----used to include other resource.
 
0
Tirupathi Rao
 
 
Answer
RequestDispatcher is an interface,In a web application 
having multiple webcomponents to handle a single request at 
time we go for RequestDispatcher.
RequestDispatcher rd=servletRequest.getRequestDispatcher
("url of the webcomponent");
rd.inculude(request,response);
rd.forward(request,response);
 
1
Yuga.reddi08
 
 
Answer
request dispatcher is used to transfer the value attributes
to servlets and jsps. the request diapatcher is use the
relative url and there is one more thing in request
dispatcher is (non -idempotant) means when u will do the
multiple submits then it will update the database again and
again so to avoid the multiple submits use the (Synchronizer
token pattern,PSG pattern,or sendRedirect)
 
1
Abhishek Taneja
 
 
Answer
RequestDispatcher is used to move/call the another 
resources (Servlets,jsps,htmls) available in the web 
applicaions 
we can get RequestDispatcher in two ways
1. servletContext.getRequestDispatcher("/path");
2. servletRequet.getRequestDispatcher("relativepath");

now we can move to another resources with the following 
methods available in RequestDispatcher
include(req,res);
forward(req,res);
 
0
Sekharbabu
 
 
Answer
RequestDispatcher is used to dispatch the request.that means
one resource take the ownership from another 
resources (Servlets,jsps,htmls) available in the web 
applicaions for handle the request.
we can get RequestDispatcher in two ways
1. servletContext.getRequestDispatcher("/absolute path");
2. servletRequet.getRequestDispatcher("relativepath");

now we can move to another resources with the following 
methods available in RequestDispatcher
include(req,res);
forward(req,res);
 
0
Bhudeep
 
 
Question
How many ways to remove the session object in the container
Rank Answer Posted By  
 Question Submitted By :: Embarq
This Interview Question Asked @   Bosch
I also faced this Question!!   © ALL Interview .com
Answer
If you are using HTTP Session then you can use 
session.remove().
But if you are using some other ways for session management 
let’s say cookies then you have to then you can setMaxAge 
to zero for the cookie.
 
0
Shyamalendu Prusty
 
 
Answer
session.invalidate() used to kill the session object,this 
method is usually called, for ex: when we logoff from an 
application.

and 

session.removeAttribute()
 
0
Ashwin Kumar J
[IBM India]
 
 
Answer
To remove the session object .
1. with the help of web.xml
 <session-timeout>time in minutes</session-timeout>
2. in programatically
 session.setMaxInactiveInterval(time in seconds)
 
to terminate immediately the session
use session.invalidate()
 
0
Sekhar Babu
[IBM India]
 
 
 
Back to Questions Page
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com