Top 80+ Solved J2EE Technologies MCQ Questions Answer
Q. Which of the following code is used to get an attribute in a HTTP Session object inservlets?
a. session.getAttribute(String name)
b. session.alterAttribute(String name)
c. session.updateAttribute(String name)
d. session.setAttribute(String name)
Q. A servlet needs to acquire a data source through a JNDI naming lookup. Which of the following is the best place to do this?
a. Constructor
b. init method
c. service method
d. doGet method
Q. What's the difference between servlets and applets? a. Servlets executes on Servers, where as
a. Applets executes on Browser
b. Servlets have no GUI, where as an Applet has GUI
c. Servlets creates static web pages, where as Applets creates dynamic web pages
d. Servlets can handle only a single request, where as Applet can handle multiple requests
Q. Which of the following code retrieves the body of the request as binary data?
a. DataInputStream data = new InputStream()
b. DataInputStream data = response.getInputStream()
c. DataInputStream data = request.getInputStream()
d. DataInputStream data = request.fetchInputStream()
Q. When destroy() method of a filter is called?
a. The destroy() method is called only once at the end of the life cycle of a filter
b. The destroy() method is called after the filter has executed doFilter method
c. The destroy() method is called only once at the begining of the life cycle of a filter
d. The destroyer() method is called after the filter has executed
Q. Which of the following is true about servlets?
a. Servlets execute within the address space of web server
b. Servlets are platform-independent because they are written in java
c. Servlets can use the full functionality of the Java class libraries
d. Servlets execute within the address space of web server, platform independent and uses the functionality of java class libraries
Q. Which method is used to specify before any lines that uses the PrintWriter?
a. setPageType()
b. setContextType()
c. setContentType()
d. setResponseType()
Q. Which of the following are the session tracking techniques?
a. URL rewriting, using session object, using response object, using hidden fields
b. URL rewriting, using session object, using cookies, using hidden fields
c. URL rewriting, using servlet object, using response object, using cookies
d. URL rewriting, using request object, using response object, using session object
Q. A servlet maintain session in
a. Servlet container
b. Servlet context
c. Servlet request heap
d. Servlet response heap
Q. Servlet mapping defines
a. an association between a URL pattern and a servlet
b. an association between a URL pattern and a request page
c. an association between a URL pattern and a response page
d. All of the above
Q. The life cycle of a servlet is managed by
a. servlet context
b. servlet container
c. the supporting protocol (such as http or https)
d. all of the above
Q. The init parameter name and value pairs that are defined in web.xml file are handled by
a. ServletConfig object
b. ServletContext object
c. ServletRequest object
d. ServletResponse object
Q. How many ServletContext objects are available for an entire web application?
a. One each per servlet
b. One each per request
c. One each per response
d. Only one
Q. Which of the following package contains servlet classes?
a. javax.servlet
b. javax.servlet.http
c. Both of the above
d. None of the above
Q. Which page directive should be used in JSP to generate a PDF page?
a. contentType
b. generatePdf
c. typePDF
d. contentPDF