Servlet

Java Servlet Projects

Servlet Project 3

Servlet Objective Questions And Answers
More interview questions and answers

Choose correct ansewrs 1. Servlet is a Java technology based Web component. 2. Servlet servlets are platform-independent 3. Servlet has run on Web server which has a containers 4. Servlets interact with Web clients via a request/response using HTTP protocol. A.1,2,3,4 B.1,2,3 C.1,3,4 D.None

A.1,2,3,4

Which of the following are interface? 1.ServletContext 2.Servlet 3.GenericServlet 4.HttpServlet A.1,2,3,4 B,1,2 C.1,3,4 D.1,4

B,1,2

Which of the following are class? 1.ServletContext 2.Servlet 3.GenericServlet 4.HttpServlet A.1,2,3,4 B,1,2 C.3,4 D.1,4

C.3,4

Which of the following methods are main methods in life cycle of servlet? 1.init() 2 .service() 3.destroy() 4.srop() 5.wait() A.1,2,3,4,5 B,1,2,3 C.3,4,5 D.1,4,5

B,1,2,3

init(),service() and destroy()methods are define in 1.javax.servlet.Servlet interface 2.javax.servlet.ServletHttp class 3.javax.servlet.ServletRequest interface 4.javax.servlet.ServletResponse interface A.1,2,3,4,5 B,1 C.3,4,5 D.1,4,5

B.1

Int init() ,.service() and destroy() methods which methods are call only once at life cycle of servlets 1.init() 2.service() 3.destroy() A.1,2,3 B,1,3 C.2 D.None

B.1,3

During initialization of servlet a servlet instance can throw 1.An UnavailableException 2 A ServletException 3.Both 4.None

3.Both

Is Servlet thread Safe? 1.Yes 2.No 3.None

2.No

ServletContext is 1. an Interface 2.A container which is used to store an object so that it is available for whole application 3.A container which is used to store an object so that it is available for session only. 4.A container which is used to store an object so that it is available for request only. A.1,2,3,4 B.1,2 C.1,3,4 D.4

B.1,2

A servlet can access the headers of an HTTP request through which following methods of the HttpServletRequest interface: 1.getHeader() 2 getHeaders() 3.getHeaderNames() 4.All 5.None

4.All

Which option is true for HttpServletRequest interface to access Path information? 1.getContextPath() 2.getServletPath() 3.getPathInfo() 4.None

1.getContextPath()
2.getServletPath()
3.getPathInfo()

Choose correct header methods to set header which is define into HttpServletResponse interface : 1. setIntHeader() 2.setDateHeader() 3.addIntHeader() 4. addDateHeader() 5.All 6.None

5.All

Which is not method of HttpServletRespons interface : 1. sendRedirect() 2. sendError() 3. setIntHeader() 4. setDateHeader() 5. addIntHeader() 6.None

1. sendRedirect() 
2. sendError()

Which syntax is correct to configure filter in web.xml 1. R4RLoginFilter com.acme.R4RLoginFilter 2. R4RLoginFilter com.acme.R4RLoginFilter 3. < configure-filter > R4RLoginFilter com.acme.R4RLoginFilter 4. R4RLoginFilter com.acme.R4RLoginFilter

1.

R4RLoginFilter
com.acme.R4RLoginFilter

Which syntax is correct for mapping filter in web.xml 1. R4RLoginFilter com.acme.R4RLoginFilter 2. R4RLoginFilter com.acme.R4RLoginFilter 3. R4RLoginFilter R4RLoginFilter 4. R4RLoginFilter com.acme.R4RLoginFilter

3.
 R4RLoginFilter 
R4RLoginFilter

Which is correct syntax for include a file? 1. String path = “/abc.jsp; RequestDispatcher rd = context.getRequestDispatcher(path); rd.include(request, response); 2. String path = “/abc.jsp; RequestDispatcher rd = request.getRequestDispatcher(path); rd.include(request, response); 3. String path = “/abc.jsp; RequestDispatcher rd = response.getRequestDispatcher(path); rd.include(request, response); 4. String path = “/abc.jsp; RequestDispatcher rd = session.getRequestDispatcher(path); rd.include(request, response);

1.
String path = “/abc.jsp;
RequestDispatcher rd = context.getRequestDispatcher(path);
rd.include(request, response);