Unit 5 AJP
Unit 5 AJP
1|Page
UINIT 5
2|Page
UINIT 5
10. A JSP page uses the java.util.ArrayList class many times. Instead of referring the class by its
complete package name each time, we want to just use ArrayList. Which attribute of page directive
must be specified to achieve this.
- A. import
- B. include
- C. pageContext
- D. contentType
- Answer: A. import
12. A user types the URL http://www.msbte.com/result.php. Which HTTP request gets generated?
- A. POST method
- B. GET method
- C. PUT method
- D. DELETE method
- Answer: B. GET method
3|Page
UINIT 5
13. A ___________________ is a small piece of information that is persisted between the multiple
client requests.
- A. Session
- B. Cookie
- C. Attribute
- D. Parameter
- Answer: B. Cookie
16. An image file representing a company's logo has to be uploaded to the server. Which of the
following HTTP methods can be used in this situation?
- A. doGet()
- B. doPost()
- C. doPut()
- D. doDelete()
- Answer: C. doPut()
4|Page
UINIT 5
17. An object of Which is created by the web container at the time of deploying the project?
- A. ServletConfig
- B. ServletContext
- C. HttpSession
- D. HttpServletRequest
- Answer: B. ServletContext
5|Page
UINIT 5
22. CGI was expensive in terms of ___________and _________ to create a separate process for each
client request.
- A. Process, Memory
- B. Memory, Resource
- C. Time, Space
- D. CPU, Storage
- Answer: B. Process, Memory
6|Page
UINIT 5
26. Cookie is the piece of information which stores the session-related data like_______________.
- A. username, password
- B. time, date
- C. username, password, time, date
- D. IP address, browser type
- Answer: C. username, password, time, date
7|Page
UINIT 5
31. Dynamic interception of requests and responses to transform the information is done by
- A. Servlet filter
- B. RequestDispatcher
- C. ServletContextListener
- D. HttpSessionListener
- Answer: A. Servlet filter
8|Page
UINIT 5
9|Page
UINIT 5
37. getSession() method with true as a parameter will return the appropriate session object when
________________.
- A. session is existing
- B. session is new
- C. session is invalidated
- D. session is expired
- Answer: A. session is existing
10 | P a g e
UINIT 5
40. How can we get context init parameter and run some code before the rest of the application can
service a client?
- A. ServletContextListener
- B. HttpSessionListener
- C. ServletRequestListener
- D. ServletConfigListener
- Answer: A. ServletContextListener
11 | P a g e
UINIT 5
12 | P a g e
UINIT 5
48. Identify the correct syntax of the service() method of the servlet class.
- A. void service(ServletRequest req, ServletResponse res)
- B. void service(ServletConfig config, ServletRequest req, ServletResponse res)
- C. void service(HttpServletRequest req, HttpServletResponse res)
- D. void service(ServletResponse res, HttpServletRequest req)
- Answer: C. void service(HttpServletRequest req, HttpServletResponse res)
50. If you want to track active sessions or how many users are there? which listener should you use.
- A. HttpSessionListener
- B. ServletContextListener
- C. ServletRequestListener
- D. ServletConfigListener
- Answer: A. HttpSessionListener
13 | P a g e
UINIT 5
51. In a web application, running in a web server, who is responsible for creating request and
response object?
- A) Container
- B) Server
- C) Servlet
- D) Web.xml
Answer: C) Servlet
53. In HTTP Request, which asks for the loopback of the request message, for testing or
troubleshooting?
- A) DEBUG
- B) TRACE
- C) OPTIONS
- D) CONNECT
Answer: B) TRACE
14 | P a g e
UINIT 5
54. In JSP, a Canvas object provides access to a Graphics object via one of its method called:
- A) draw()
- B) render()
- C) paint()
- D) display()
Answer: C) paint()
15 | P a g e
UINIT 5
58. In which of these getAttribute() and setAttribute() methods are not defined?
- A) HttpSession
- B) ServletConfig
- C) ServletContext
- D) HttpServletRequest
Answer: B) ServletConfig
59. In which phase of JSP life cycle, JSP page turns into servlet?
- A) JSP Compilation
- B) JSP Initialization
- C) JSP Execution
- D) JSP Destruction
Answer: D) javax.servlet.Servlet
16 | P a g e
UINIT 5
61. Java servlets are an efficient and powerful solution for creating ____________ for the web.
- A) Static content
- B) Dynamic content
- C) Text files
- D) Audio files
62. javax.servlet package does not contain the following class or interface.
- A) HttpServlet
- B) ServletContext
- C) ServletRequest
- D) HttpSession
Answer: B) ServletContext
17 | P a g e
UINIT 5
65. JSP containers are required to support ______________ different formats of JSP syntax.
- A) One
- B) Two
- C) Three
- D) Four
Answer: B) Two
Answer: C) HttpServletRequest
18 | P a g e
UINIT 5
69. JSP is not governed by the syntax and semantics defined by the ______________ specifications.
- A) HTML
- B) Java SE
- C) Java EE
- D) Java 2
Answer: D) Java 2
Answer: D) Servlet
19 | P a g e
UINIT 5
73. JSP supports ____________ implicit objects that JSP container makes available to developers in
each page.
- A) 5
- B) 7
- C) 9
- D) 11
Answer: C) 9
20 | P a g e
UINIT 5
76. Name a class that includes the getSession() method that is used to get the HttpSession.
- A) HttpSessionRequest
- B) HttpSessionManager
- C) HttpSessionHandler
- D) HttpServletRequest
Answer: D) HttpServletRequest
77. Name the class that can be used to get the cookies from the client browser.
- A) HttpServletResponse
- B) HttpSession
- C) CookieManager
- D) HttpServletRequest
Answer: D) HttpServletRequest
78. Name the HTTP method that sends the same response as the request.
- A) OPTIONS method
- B) HEAD method
- C) TRACE method
- D) CONNECT method
21 | P a g e
UINIT 5
79. Name the HTTP method used to send resources to the server.
- A) UPLOAD method
- B) POST method
- C) PUT method
- D)SUBMIT method
80. Name the interface that is used to get initialization parameters for Servlet.
- A) ServletContext
- B) ServletConfig
- C) ServletParameter
- D) ServletInitializer
Answer: B) ServletConfig
81. Name the location of compiled class files within a JAR file?
- A) /META-INF/classes
- B) /WEB-INF/classes
- C) /CLASS-INF/classes
- D) /JAR-INF/classes
Answer: B) /WEB-INF/classes
22 | P a g e
UINIT 5
82. Name the method defined in the HttpServletResponse class that may be used to set the content
type.
- A) setContentType
- B) addContentType
- C) setResponseType
- D) contentTypeSetter
Answer: A) setContentType
83. On typing a URL on the address bar, which HTTP request gets generated?
- A) POST method
- B) PUT method
- C) GET method
- D) REQUEST method
Answer: B) doGet()
23 | P a g e
UINIT 5
85. Servlets are webpages generated by the web server In response to the requests sent by the:
- A) User
- B) Client
- C) Browser
- D) Server
Answer: B) Client
88. State true or false for the following statements in Java. i) Java beans slow down the software
development process. ii) Java Servlets do not have a built-in multithreading feature.
- A) i-True, ii-False
- B) i-False, ii-True
- C) i-True, ii-True
- D) i-False, ii-False
24 | P a g e
UINIT 5
89. The doGet() Extracts values of the parameter type and number by using ___________.
- A) request.getParameterValues()
- B) request.getParameters()
- C) request.getParamValues()
- D) request.getParams()
Answer: A) request.getParameterValues()
91. The getSession() method with its parameter [getSession(true)]. It will return the appropriate
session object when ____.
- A) the session is existing
- B) the session is new
- C) the session is null
- D) the session is invalid
Answer: B) the session is new
25 | P a g e
UINIT 5
94. The init parameter name and value pairs that are defined in web.xml file are handled by
______________ Object.
- A) ServletConfig
- B) ServletContext
- C) ServletRequest
- D) HttpServletRequest
Answer: A) ServletConfig
95. The Java __________ specification defines an application programming interface for
communication between the Web server and the application program.
- A) JavaServer Faces (JSF)
- B) JavaServer Pages (JSP)
- C) Java API for Servlets
- D) Java Naming and Directory Interface (JNDI)
26 | P a g e
UINIT 5
96. The javax.servlet.jsp package has two interfaces found in the following?
- A) JspPage & JspServlet
- B) JspFile & JspTag
- C) HttpJspPage & JspTag
- D) JspWriter & JspFactory
97. The JspPage interface defines the __________ and ____ methods which the page writer can use
in their pages and are invoked in much the same manner as the ____ and _____ methods of a
servlet.
- A) init(), destroy(), service(), doGet()
- B) init(), destroy(), jspInit(), jspDestroy()
- C) jspInit(), jspDestroy(), service(), doGet()
- D) jspInit(), jspDestroy(), init(), destroy()
27 | P a g e
UINIT 5
100. The maximum size of data that can be sent by doGet() of HTTP request is:
- A) 128 bytes
- B) 240 bytes
- C) 512 bytes
- D) 1024 bytes
101. The parameters can be passed to an applet by using <PARAM> tag in the following way:
- A) <PARAM NAME=parameter_name VALUE=parameter_value>
- B) <PARAMETER NAME=parameter_name VALUE=parameter_value>
- C) <PARAM NAME:parameter_name VALUE:parameter_value>
- D) <PARAMETER NAME:parameter_name VALUE:parameter_value>
28 | P a g e
UINIT 5
Answer: C) Initialization
A) Configuration
B) Initialization
C) Destruction
D) Service
Answer: A) Configuration
104. The whole life cycle of a servlet breaks up into 3 phases: 5 N R 1 Initialization, Service ,
Destroy Edit
29 | P a g e
UINIT 5
105. The _______ method is called when the servlet is first created, and is not called again as long as
the servlet is not destroyed.
A) setup()
B) start()
C) init()
D) begin()
Answer: C) init()
106. These methods doGet(), doPost(), doHead(), doDelete(), doTrace() are used in?
A) HttpServlet
B) HttpHandler
C) HttpRequest
D) HttpMethod
Answer: A) HttpServlet
A) java.lang
B) javax.servlet
C) java.util
D) javax.http
Answer: B) javax.servlet
30 | P a g e
UINIT 5
108. This method is called once just before the servlet is unloaded and taken out of service.
A) unload()
B) stop()
C) destroy()
D) end()
Answer: C) destroy()
109. TLDs are used by a ___________________ to validate the tags and by JSP page development
tools
A) web container
B) web server
C) web browser
D) web client
Answer: A) web container
110. To compile a Java servlet program, the ___________ file must be in the classpath.
A) servlet.xml
B) web.xml
C) servlet.jar
D) java.jar
Answer: C) servlet.jar
31 | P a g e
UINIT 5
111. To get the servlet environment information 5 N R 1 ServletContext object is used Edit
A) ServletConfig
B) HttpRequest
C) ServletContext
D) HttpServletResponse
Answer: C) ServletContext
A) Database Server
B) Web Server
C) Application Server
D) FTP Server
Answer: B) Web Server
113. What are the mechanisms available in the ServletContextListener interface? 5 N R 1
contextInitialized(), contextDestroyed() Edit
A) start(), stop()
B) init(), destroy()
C) contextStart(), contextStop()
D) contextInitialized(), contextDestroyed()
Answer: D) contextInitialized(), contextDestroyed()
32 | P a g e
UINIT 5
114. What are the correct statements about filters? 5 N R 1 All of these Edit
115. What are the true sentences about Session-Id? 5 N R 1 All of these Edit
33 | P a g e
UINIT 5
117. What is the difference between servlets and applet? 1) Servlets execute on server, whereas
applets execute on the browser 2) Servlets have no GUI, whereas Applets have GUI 3) Servlets
create static web pages, whereas applets create dynamic pages 4) Servlets can handle only a single
request, whereas applets can handle multiple requests 5 N R 1 1,2 are correct Edit
A) 1,2,3,4
B) 1,2,3
C) 1,2,4
D) 1,2
Answer: A) 1,2,3,4
118. What is invoked via HTTP on the Web server computer when it responds to requests from a
user's Web browser?
A) Java Applet
B) Java Servlet
C) HTML Page
D) JavaScript
Answer: B) Java Servlet
A) HttpSession
B) ServletSession
C) WebSession
D) Session
Answer: A) HttpSession
34 | P a g e
UINIT 5
120. What is a servlet? 5 N R 1 Servlets are small programs used for developing and executing web
applications. Edit
A) Servlets are small programs used for developing and executing web applications.
B) Servlets are large programs used for system development.
C) Servlets are used for database management.
D) Servlets are used for network programming.
Answer: A) Servlets are small programs used for developing and executing web applications.
122. What does JSP stand for? 5 N R 1 Java Server Pages Edit
35 | P a g e
UINIT 5
123. What method is used to specify a container's layout in JSP? 5 N R 1 setLayout() Edit
A) setLayout()
B) setDesign()
C) setContainer()
D) setFormat()
Answer: A) setLayout()
124. What programming language(s) or scripting language(s) does Java Server Pages (JSP)
support?
A) Java only
B) Java and JavaScript
C) Java and HTML
D) Java, JavaScript, and HTML
Answer: A) Java only
125. What servlet processor was developed by Apache Foundation and Sun?
A) Apache Server
B) Tomcat Server
C) GlassFish Server
D) Apache Tomcat
Answer: D) Apache Tomcat
36 | P a g e
UINIT 5
126. What value does readLine() return when it has reached the end of a file in JSP?
A) True
B) False
C) Null
D) EndOfFile
Answer: C) Null
A) Client-side
B) Server-side
C) In the database
D) In cookies
Answer: B) Server-side
37 | P a g e
UINIT 5
129. Which method returns names of the request parameters as Enumeration of String objects
A) getParameterNames
B) request.getParameterNames
C) parameterNames
D) getRequestParameters
Answer: A) getParameterNames
130. Which among the below is the class of the javax.servlet package 5 N R 1 GenericServlet Edit
A) HttpServlet
B) ServletContext
C) ServletConfig
D) GenericServlet
Answer: D) GenericServlet
131. Which are true about tag libraries in web applications? 5 N R 1 all of the above Edit
A) Name
B) ID
C) Type
D) Value
Answer: A) Name
38 | P a g e
UINIT 5
133. Which cookie is valid for a single session only; it is removed each time when the user closes the
browser?
A) Persistent cookie
B) Non-persistent cookie
C) Temporary cookie
D) Session cookie
Answer: D) Session cookie
134. Which HTTP method gets invoked when a user clicks on a link? Select the one correct answer
A) POST method
B) PUT method
C) DELETE method
D) GET method
Answer: D) GET method
135. Which HTTP method is sent by the browser that asks the server to get the page only?
A) get
B) post
C) fetch
D) retrieve
Answer: A) get
39 | P a g e
UINIT 5
136. Which interface declares the life cycle method of the servlet?
A) ServletConfig
B) ServletContext
C) ServletLifeCycle
D) Servlet
Answer: D) Servlet
A) HttpServletRequest
B) HttpSession
C) ServletRequest
D) ServletContext
Answer: A) HttpServletRequest
A) HttpRequest
B) ServletRequest
C) ServletConfig
D) Servlet
Answer: D) Servlet
40 | P a g e
UINIT 5
139. Which is the least visibility scope for JavaBean in JSP 5 N R 1 Page Edit
A) Request
B) Page
C) Application
D) Session
Answer: B) Page
140. Which is not the method in servlet to handle HTTP requests 5 N R 1 doShow() Edit
A) doGet()
B) doPost()
C) doService()
D) doShow()
Answer: D) doShow()
141. Which JSP tag is used to transfer processing to another JSP page? 5 N R 1
<jsp:forward> Edit
A) <jsp:include>
B) <jsp:redirect>
C) <jsp:forward>
D) <jsp:transfer>
Answer: C) <jsp:forward>
41 | P a g e
UINIT 5
142. Which life cycle method is used to process a client's request? 5 N R 1 service() Edit
A) init()
B) process()
C) service()
D) execute()
Answer: C) service()
143. Which methods are central to the life cycle of a servlet? 5 N R 1 init(), service(), and destroy()
Edit
144. Which method decides whether doGet() or doPost() method to call? 5 N R 1 service Edit
A) determineMethod()
B) resolveRequest()
C) service()
D) processRequest()
Answer: C) service()
42 | P a g e
UINIT 5
145. Which method does not exist on the HttpServlet class? 5 N R 1 init() Edit
A) init()
B) service()
C) doGet()
D) initServlet()
Answer: D) initServlet()
A) process()
B) execute()
C) handle()
D) service()
Answer: D) service()
147. Which method is used in the servlet class to retrieve the input values from an HTML page?
A) getRequestParameters()
B) extractInputs()
C) getInputValues()
D) request.getParameter()
Answer: D) request.getParameter()
43 | P a g e
UINIT 5
148. Which method is used to end the servlet lifecycle 5 N R 1 destroy Edit
A) stop()
B) end()
C) finish()
D) destroy()
Answer: D) destroy()
149. Which method is used to extract cookies from a request? 5 N R 1 getCookies() Edit
A) getRequestCookies()
B) extractCookies()
C) getCookies()
D) request.getCookies()
Answer: D) request.getCookies()
150. Which method is used to specify before any lines that use the PrintWriter? 5 N R 1
setContentType() Edit
A) setContentType()
B) setPrintWriter()
C) setOutputType()
D) setWriterType()
Answer: A) setContentType()
44 | P a g e
UINIT 5
Answer: c) getSession()
152. Which method of HttpServletResponse is used to redirect an HTTP request to another URL?
- a) forward()
- b) sendRedirect()
- c) redirectTo()
- d) location()
Answer: b) sendRedirect()
153. Which method of the component class is used to set the position and size of a component in
JSP?
- a) setPosition()
- b) setSize()
- c) setBounds()
- d) setCoordinates()
Answer: c) setBounds()
45 | P a g e
UINIT 5
155. Which method allows the client to send data of unlimited length to the web page server a single
time?
- a) doGet()
- b) doPost()
- c) sendToServer()
- d) sendData()
Answer: b) doPost()
Answer: b) It is multi-threaded.
46 | P a g e
UINIT 5
Answer: a) include
159. Which of the following are interfaces? (ServletContext, Servlet, GenericServlet, HttpServlet)
- a) ServletContext, Servlet
- b) Servlet, GenericServlet
- c) ServletContext, GenericServlet
- d) ServletContext, HttpServlet
47 | P a g e
UINIT 5
Answer: a) URL rewriting, using session object, using cookies, using hidden fields
161. Which of the following correctly represents the following JSP statement. <%=x%>
- a) <jsp:expression>x</jsp:expression>
- b) <%=$x%>
- c) <%=x%>
- d) <jsp:output>x</jsp:output>
Answer: c) <%=x%>
162. Which of the following implicit objects is not available to a JSP page by default?
- a) context
- b) request
- c) response
- d) session
Answer: a) context
48 | P a g e
UINIT 5
163. Which of the following is an approach for state maintenance in Web applications?
- a) Session management
- b) Cookie management
- c) URL rewriting
- d) All of the above
164. Which of the following is legal JSP syntax to print the value of i?
- a) <%int i = 1;%>
- b) <%= i %>
- c) <%out.println(i);%>
- d) <jsp:output>i</jsp:output>
Answer: a) DHTML
49 | P a g e
UINIT 5
166. Which of the following is used to redirect the response from a servlet to a JSP page?
- a) redirect()
- b) forward()
- c) sendRedirect()
- d) redirectToJSP()
Answer: c) response.sendRedirect()
167. Which of the following JSP variables are not available within a JSP expression?
- a) httpsession
- b) request
- c) response
- d) pageContext
Answer: a) httpsession
168. Which of the following methods does not exist in HttpServlet class?
- a) init
- b) service
- c) doGet
- d) destroy
Answer: a) init
Answer: b) invalidate( )
50 | P a g e
UINIT 5
170. Which of the following methods are main methods in the life cycle of servlet? (init(), service(),
destroy())
- a) init() and service()
- b) service() and destroy()
- c) init(), service(), and destroy()
- d) init() only
171. Which of the following packages are required to create servlets in Java?
- a) java.servlet, java.servlet.http
- b) javax.servlet, javax.servlet.http
- c) servlet, servlet.http
- d) java.servlets, java.servlets.http
Answer: b) javax.servlet, javax.servlet.http
172. Which of these is a protocol for breaking and sending packets to an address across a network?
- a) UDP/IP
- b) TCIP/IP
- c) FTP
- d) HTTP
Answer: b) TCIP/IP
51 | P a g e
UINIT 5
174. Which of these methods can be called multiple times in a servlet's life cycle?
- a) init()
- b) service()
- c) doGet()
- d) destroy()
Answer: b) service()
175. Which of these protocols uses the service() method to process the request in servlet?
- a) HTTP
- b) FTP
- c) TCP
- d) UDP
Answer: a) HTTP
176. Which packages represent interfaces and classes for servlet API?
-a) javax.servlet
- b) javax.servlet.http
- c) both a and b
- d) servlet
Answer: c) both a and b
177. Which servlet processor was developed by Apache Foundation and Sun?
- a) Apache Tomcat
- b) Jetty
- c) GlassFish
- d) WebLogic
Answer: a) Apache Tomcat
52 | P a g e
UINIT 5
178. Which statements about HttpSession objects are true? (1. A session may become invalid due to
inactivity. 2. A new session is created each time a user makes a request. 3. A session may become
invalid as a result of a specific call by a servlet. 4. Multiple requests made from the same browser
may have access to the same session object.)
- a) 1, 3, 4 are correct
- b) 2, 3, 4 are correct
- c) 1, 2, 3 are correct
- d) 1, 2, 4 are correct
53 | P a g e
UINIT 5
182. ______ Method returns true if the server created the session and it has not yet been accessed by
the client.
- a) isNew()
- b) isFresh()
- c) isAlive()
- d) isNotUsed()
Answer: a) isNew()
183. _______ is a small piece of information that is passed back & forth in HTTP request &
response.
- a) Session
- b) Cookie
- c) Token
- d) Identifier
Answer: b) Cookie
Answer: a) Servlet
54 | P a g e
UINIT 5
185. ___________ is a technology for developing web pages that supports dynamic content which
helps developers to insert Java code in HTML pages by making use of special tags <% _________
%>.
- a) JSF
- b) JSP
- c) ASP
- d) PHP
Answer: b) JSP
188. ______________ class provides functionality that makes it easy to handle requests and
responses.
- a) ServletRequest
- b) HttpServlet
- c) GenericServlet
- d) HttpServletResponse
Answer: c) GenericServlet
55 | P a g e
UINIT 5
189. ______________Defines page-dependent attributes, such as scripting language, error page, and
buffering requirements.
- a) <%@ page ... %>
- b) <%@ attribute ... %>
- c) <%@ directive ... %>
- d) <%@ definition ... %>
190. ________________ method executes at the end of the servlet life cycle.
- a) finish()
- b) complete()
- c) end()
- d) destroy()
Answer: d) destroy()
56 | P a g e
UINIT 5
57 | P a g e
UINIT 5
194. Consider the following program and identify the missing method name
****** if you want to implement HTTP POST.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
Answer: a) doPost()
58 | P a g e
UINIT 5
195. In the following Java program, fill in the statement showing ******. Select any one option
from the given options.
import java.io.*;
import java.util.*;
import javax.servlet.*;
Answer: b) request.getParameter(pname)
59 | P a g e
UINIT 5
196. In the following Java program, fill in the statement showing ***. Select any one option from
the given options.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
Answer: b) response.setContentType("text/html");
60 | P a g e
UINIT 5
Answer: b) javax.servlet
Answer: b) doPost()
61 | P a g e
UINIT 5
199. <HTML>
<BODY>
<FORM ACTION="someaction" METHOD="post">
<INPUT TYPE="hidden" NAME="tag1" VALUE="value1">
<INPUT TYPE="hidden" NAME="tag2" VALUE="value2">
<INPUT TYPE="submit">
</FORM>
</BODY>
</HTML>
When you open this HTML document in a browser, the input types marked as hidden will be
visible.
- a) True
- b) False
Answer: b) False
62 | P a g e
UINIT 5
200. <HTML>
<HEAD><TITLE>Hello</TITLE></HEAD>
<BODY>
<H1>
<% if (request.getParameter("name") == null) {
out.println("Hello World");
} else {
out.println("Hello, " + request.getParameter("name"));
} %>
</H1>
</BODY></HTML>
What file extension will be saved with this JSP document?
- a) .jsp
- b) .html
- c) .java
- d) .jspf
Answer: a) .jsp
63 | P a g e