This post originated from an RSS feed registered with Java Buzz
by instanceof java.
Original Post: Java Servlet Interview Questions
Feed Title: Instance Of Java
Feed URL: http://feeds.feedburner.com/blogspot/TXghwE
Feed Description: Instance of Java. A place where you can learn java in simple way each and every topic covered with many points and sample programs.
Request parameters are used by the servlet to receive data from client to process the request.
Some specific data must be supplied to the servlet at the time of initialization of the servlet and this data is specific to the client.But data is not supplied by the client via request parameters
Use initialization parameters to supply the data to the servlet at the time of initialization of the servlet. initialization parameters are set in deployment descriptor (Web.xml).
Servlet can access these parameters during the run time
Request parameters change form Request to request
Initialization parameters change from servlet to servlet.
Yes we can define a constructor in servlet but we can not call the constructor explicitly because servlet container will create the object of servlet so it will be called by the servlet container.
5. Can we call destroy() method inside init() method of a servlet. If yes what will happen?
Yes we can call destroy() method inside a init() method.
Actually container will call destroy() method if we call that method explicitly nothing will happen.
If we override destroy() method and called from init(). method will be called and code will be executed.
6.What are the difference between GenericServlet and HttpServlet?
GenericServlet
HttpServlet
Abstract Class
Abstract Class
Protocol Independent
Http Protocol Dependent
Subclass of Servlet
Subclass of GenericServlet
public void service(ServletRequest req,ServletResponse res ).
Supports public void service() and protected void service(), doGet(),doPost(),doPut(),doDelete(),doHead(),doTrace(),doOptions()etc.
7.What are the differences between doGet() and doPost()?