The Artima Developer Community
Sponsored Link

Java Buzz Forum
Java Servlet Interview Questions

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
instanceof java

Posts: 576
Nickname: instanceof
Registered: Jan, 2015

instanceof java is a java related one.
Java Servlet Interview Questions Posted: May 18, 2015 10:38 AM
Reply to this message Reply

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.
Latest Java Buzz Posts
Latest Java Buzz Posts by instanceof java
Latest Posts From Instance Of Java

Advertisement

1.Explain Servlet life cycle in java.

  • Servlet engine controls the life cycle of servlet
  • Servlet life cycle is described by three life cycle methods under 5 life cycle phases
  • life cycle methods are
  1. init(ServletConfig obj)
  2. service(servletRequest, servletResponse)
  3. destroy() 

  • When ever somethings happens in the life of servlet. servlet engine calls these methods on the servlet instance and hence the name.

Read more here: Servlet Life Cycle

2.What is ServletConfig ?

  • 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.

Read more at : ServletConfig

3. What is ServletContext?

  • We can deploy multiple web applications in a servlet container.
  • Each web application contains its own resources in a separate  environment. This environment called ad Web Application context or ServletContext.
  • The resources belongs to the one web application context are not available to the other web application context.
  • A Servlet context contains zero or more number of servlets. For every servlet object the container creates separate ServletConfig object.
Read More at : ServlectContext

4. Can we define a Constructor in 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()?



doGet() doPost()
protected void doGet(HttpServletRequest req, HttpServletResponse resp)throws ServletException, java.io.IOException Protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
handles client's GET request handles client's POST request
Request parameters appended to the URL and sent along with header information Request parameters are submitted via form.
Request Parameters are not encrypted Request Parameters are encrypted
Maximum size of data that can be sent using doget is 240 bytes There is no maximum size for data.



    Read: Java Servlet Interview Questions

    Topic: Streaming data into HPCC using Java Previous Topic   Next Topic Topic: The Bet With Typesafe That Got Me Into Building Akka

    Sponsored Links



    Google
      Web Artima.com   

    Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use