Sample Questions Best site for GRE, LSAT, SAT, GMAT, TOEFL, CCNA, CCSA and interview sample questions  

Technical Sample Questions : C |  C++ |  Oracle |  Java | Unix |  Operating Systems |  Data Structure

Java Sample Questions ›› Java Servlet Sample Questions

Technical Java Sample Questions : Java Servlet Sample Questions

Java Servlet sample questions and answers have been provided here for the reference of the students. These questions are different from the JSP sample questions and J2EE sample questions.

  1. Explain the life cycle methods of a Servlet.


    The javax.servlet.Servlet interface defines the three methods known as life-cycle method.

    Method 1: public void init(ServletConfig config) throws ServletExceptionpublic

    Method 2: void service( ServletRequest req, ServletResponse res) throws ServletException, IOExceptionpublic

    Method 3: void destroy()

    First the servlet is constructed, then initialized with the init() method.

    Any request from client are handled initially by the service() method before delegating to the doXxx() methods in the case of HttpServlet.

    The servlet is removed from service, destroyed with the destroy() method, then garbage collected and finalized.

  2. What is the difference between the getRequestDispatcher(String path) method of javax.servlet.ServletRequest interface and javax.servlet.ServletContext interface?

    Answer: The getRequestDispatcher(String path) method of javax.servlet.ServletRequest interface accepts parameter the path to the resource to be included or forwarded to, which can be relative to the request of the calling servlet.If the path begins with a "/" it is interpreted as relative to the current context root.The getRequestDispatcher(String path) method of javax.servlet.ServletContext interface cannot accepts relative paths.All path must sart with a "/" and are interpreted as relative to curent context root.

  3. Explain the directory structure of a web application.

    Answer: The directory structure of a web application consists of two parts. A private directory called WEB-INFA public resource directory which contains public resource folder. WEB-INF folder consists of 1.web.xml2.classes directory3.lib directory.

  4. What are the common mechanisms used for session tracking?

    Answer: CookiesSSL sessionsURL- rewriting

  5. Explain ServletContext.

    Answer: ServletContext interface is a window for a servlet to view its environment. A servlet can use this interface to get information such as initialization parameters for the web applicationor servlet containers version. Every web application has one and only one ServletContext and is accessible to all active resource of that application.

  6. What is the difference between Difference between doGet() and doPost()?

    Answer: A doGet() method is limited with 2k of data to be sent, and doPost() method doesn't have this limitation. A request string for doGet() looks like the following: method call doesn't need a long text tail after a servlet name in a request. All parameters are stored in a request itself, not in a request string, and it's impossible to guess the data transmitted to a servlet only looking at a request string.

  7. What is the difference between HttpServlet and GenericServlet?

    Answer: A GenericServlet has a service() method aimed to handle requests. HttpServlet extends GenericServlet and adds support for doGet(), doPost(), doHead() methods (HTTP 1.0) plus doPut(), doOptions(), doDelete(), doTrace() methods (HTTP 1.1).Both these classes are abstract.

The questions and answers provided above are meant for the help of the students. Reader can also refer to Java web development sample questions for further reference.

Sample Test Questions
GRE Sample Questions
CAT Sample Questions
GMAT Sample Questions
TOEFL Sample Questions
ACT Sample Questions
SAT Sample Questions
LSAT Sample Questions
PSAT Sample Questions
MCAT Sample Questions
PMP Sample Questions
GED Sample Questions
ECDL Sample Questions
DMV Sample Questions
CCNA Sample Questions
MCSE Sample Questions
Network+ Sample Questions
A+ Sample Questions
Technical Sample Questions
WASL Sample Questions
CISA Sample Questions

Other Sample Questions
Sample Interview Questions
Sample Teacher Interview Questions
Sample Citizenship Questions
Accuplacer Sample Questions
Science Bowl sample Questions
Driving Test Sample Questions
Sample Survey Questions Sample Essay Questions
Sample Behavioral Interview Questions

Copyright © 2004-2013, Best BSQ. All Rights Reserved.