0% found this document useful (0 votes)
58 views

Unit 5 AJP

Uploaded by

manojschavan6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Unit 5 AJP

Uploaded by

manojschavan6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 63

UINIT 5

1. In which method of the servlet, connection is created?


- A. init()
- B. service()
- C. doPost()
- D. doGet()
- Answer: A. init()

2. ..................... is the first phase of the servlet life cycle.


- A. Initialization
- B. Service
- C. Destruction
- D. None of the above
- Answer: A. Initialization

3. Name the class that includes the getSession() method.


- A. HttpRequest
- B. HttpSession
- C. ServletContext
- D. HttpServletResponse
- Answer: B. HttpSession

4. A cookie contains _____________.


- A. State information of user like name, address
- B. Server IP address
- C. Session ID
- D. All of the above
- Answer: A. State information of user like name, address

1|Page
UINIT 5

5. A cookie is stored on __________ and contains state information.


- A. Server
- B. Client
- C. Both Server and Client
- D. None of the above
- Answer: B. Client

6. A Deployment descriptor describes_________________.


- A. Servlet class methods
- B. Web component settings
- C. Server configuration
- D. All of the above
- Answer: B. Web component settings

7. A JSP is transformed into a


- A. HTML page
- B. Java servlet
- C. XML document
- D. JavaScript file
- Answer: B. Java servlet

8. A JSP is translated to ________________.


- A. HTML
- B. Servlet
- C. XML
- D. JavaScript
- Answer: B. Servlet

2|Page
UINIT 5

9. A JSP page consists of which tags?


- A. Scripting tags
- B. Directive tags
- C. Both A & B
- D. None of the above
- Answer: C. Both A & B

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

11. A servlet is an instance of__________.


- A. HttpServlet
- B. ServletConfig
- C. ServletContext
- D. None of the above
- Answer: A. HttpServlet

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

14. Abbreviate the term MIME?


- A. Multipurpose Internet Mail Extension
- B. Multipurpose Internet Message Extension
- C. Multiple Internet Mail Extension
- D. Multiple Internet Message Extension
- Answer: A. Multipurpose Internet Mail Extension

15. Advantage of JSP over Servlet is____________


- A. JSP is web page scripting language and servlets are Java programs
- B. Servlets are easier to develop
- C. JSP has better performance
- D. Servlets are more secure
- Answer: A. JSP is web page scripting language and servlets are Java programs

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

18. By default, how long does a cookie last?


- A. Until the browser exits
- B. 24 hours
- C. 7 days
- D. 30 days
- Answer: A. Until the browser exits

19. By Default, How many variables are available in JSP programs?


- A. 4
- B. 6
- C. 8
- D. 10
- Answer: B. 6

20. By default, Tomcat runs on port ___________.


- A. 80
- B. 8080
- C. 8000
- D. 8888
- Answer: B. 8080

5|Page
UINIT 5

21. CGI stands for ___________


- A. Computer Graphics Interface
- B. Common Gateway Interface
- C. Centralized Gateway Interface
- D. Control Gateway Interface
- Answer: B. Common Gateway Interface

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

23. Choose the correct scopes into JSP


- A. page, request, session, application
- B. local, global, static
- C. instance, class, method
- D. inner, outer, anonymous
- Answer: A. page, request, session, application

24. Choose the correct syntax of the directive:


- A. <%@ directive_name%>
- B. &lt;% directive_name %&gt;
- C. <% directive_name %>
- D. &lt;%@ directive_name %&gt;
- Answer: D. &lt;%@ directive_name %&gt;

6|Page
UINIT 5

25. Cookie class consists __________________.


- A. name and value
- B. name, value, and path
- C. name, value, path, and domain
- D. name, value, path, domain, and expiration time
- Answer: A. name and value

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

27. Cookies can be deleted by using ________________________ Method.


- A. delete()
- B. clear()
- C. expire()
- D. setMaxAge()
- Answer: D. setMaxAge()

7|Page
UINIT 5

28. Cookies sent from ______ to _________.


- A. Server, Client
- B. Client, Server
- C. Sender, Receiver
- D. Local, Remote
- Answer: B. Client, Server

29. Different methods used by the cookie class are


- A. create(), delete(), expire()
- B. add(), remove(), clear()
- C. set(), unset(), reset()
- D. All of the above
- Answer: D. All of the above

30. During Initialization of Servlet, a servlet instance can throw ________.


- A. ServletException
- B. IOException
- C. Both A and B
- D. Neither A nor B
- Answer: C. Both A and B

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

32. Filters were officially introduced in the Servlet_______________ Specification.


- A. 2.0
- B. 2.2
- C. 2.3
- D. 3.0
- Answer: C. 2.3

33. Following method is not a valid life cycle method of JSP.


- A. jspInit()
- B. jspDestroy()
- C. jspStop()
- D. jspStart()
- Answer: C. jspStop()

34. Generic Servlet belongs to___________________ package of Java.


- A. javax.servlet
- B. java.servlet
- C. javax.http
- D. java.http
- Answer: A. javax.servlet

35. GenericServlet implements the _______ and _______.


- A. Servlet, HttpServlet
- B. Servlet, ServletConfig
- C. ServletConfig, ServletContext
- D. ServletContext, HttpSession
- Answer: B. Servlet, ServletConfig

9|Page
UINIT 5

36. getCookies is a method of which of the following?


- A. HttpServletRequest
- B. HttpServletResponse
- C. HttpSession
- D. ServletConfig
- Answer: A. HttpServletRequest

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

38. getWriter() method can be called by --------------------object.


- A. ServletRequest object
- B. ServletResponse object
- C. HttpSession object
- D. ServletConfig object
- Answer: B. ServletResponse object

39. Give examples of Application Server from the following?


- A. Apache Tomcat
- B. IBM WebSphere
- C. JBoss
- D. All of the above
- Answer: D. All of the above

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

41. How does Tomcat execute a JSP?


- A. By one of Tomcat's thread
- B. By creating a new process
- C. By using a separate thread pool
- D. By the main thread of the Java Virtual Machine
- Answer: A. By one of Tomcat's thread

42. How many characters we send through doGet()?


- A. 256
- B. 512
- C. 1024
- D. 2048
- Answer: C. 1024

11 | P a g e
UINIT 5

43. How many copies of a JSP page can be in memory at a time?


- A. One
- B. Two
- C. Three
- D. Unlimited
- Answer: A. One

44. How to send data in the get method?


- A. through headers
- B. through the request body
- C. through parameters in the URL
- D. through cookies
- Answer: C. through parameters in the URL

45. HTTP servlet uses methods like__________________.


- A. doPost(), doGet()
- B. service(), doGet()
- C. doRequest(), doResponse()
- D. processRequest(), processResponse()
- Answer: A. doPost(), doGet()

46. HttpServlet is a subclass of ____________________.


- A. GenericServlet
- B. Servlet
- C. ServletConfig
- D. ServletContext
- Answer: A. GenericServlet

12 | P a g e
UINIT 5

47. Identify the correct servlet interface.


- A. ServletConfig
- B. ServletContext
- C. ServletRequest
- D. Servlet
- Answer: D. Servlet

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)

49. If an expiration date is not explicitly assigned to a cookie __________.


- A. it is deleted when the current browser session ends
- B. it will last indefinitely
- C. it will be deleted after 24 hours
- D. it will be deleted after 7 days
- Answer: A. it is deleted when the current browser session ends

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

52. In HTTP request method, which is non-idempotent?


- A) GET method
- B) POST method
- C) PUT method
- D) DELETE method

Answer: B) POST method

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()

55. In order to run JSP, ______________ is required.


- A) Java Compiler
- B) Java Virtual Machine (JVM)
- C) Java Web Server
- D) Java Development Kit (JDK)

Answer: C) Java Web Server

56. In response to HTTP Request, servlet sends ______________.


- A) HTML content
- B) XML data
- C) HTTP Response
- D) JSON payload

Answer: C) HTTP Response

57. In which file do we define a servlet mapping?


- A) servlet-mapping.xml
- B) web.config
- C) servlet-config.xml
- D) web.xml
Answer: D) web.xml

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: A) JSP Compilation

60. init(), service(), destroy() methods are defined in ____________


- A) javax.servlet.ServletConfig
- B) javax.servlet.ServletRequest
- C) javax.servlet.ServletResponse
- D) javax.servlet.Servlet

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

Answer: B) Dynamic content

62. javax.servlet package does not contain the following class or interface.
- A) HttpServlet
- B) ServletContext
- C) ServletRequest
- D) HttpSession

Answer: B) ServletContext

63. JSDK stands for:


- A) Java Standard Development Kit
- B) Java Server Development Kit
- C) Java Servlet Development Kit
- D) Java Software Development Kit
Answer: C) Java Servlet Development Kit

64. JSP basically used to ______________.


- A) Develop client-side scripts
- B) Develop static web pages
- C) Develop server pages
- D) Develop mobile applications

Answer: C) Develop server pages

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

66. JSP embeds in ______________ in ______________.


- A) Java, XML
- B) HTML, Java
- C) Java, HTML
- D) XML, HTML

Answer: C) Java, HTML

67. JSP implicit object associated with the request is:


- A) HttpRequest
- B) HttpServlet
- C) HttpServletRequest
- D) HttpResponse

Answer: C) HttpServletRequest

18 | P a g e
UINIT 5

68. JSP includes a mechanism for defining ______________ or custom tags.


- A) Static attributes
- B) Dynamic attributes
- C) Final attributes
- D) Constant attributes
Answer: B) Dynamic attributes

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

70. JSP is transformed into _____________.


- A) JavaScript
- B) Java Applet
- C) Java Servlet
- D) Java Bean

Answer: C) Java Servlet

71. JSP page compiled and it turns into ______________.


- A) JSP Script
- B) JSP Code
- C) JSP Output
- D) Servlet

Answer: D) Servlet

19 | P a g e
UINIT 5

72. JSP Start and end With the Symbol:


- A) &lt;? ?&gt;
- B) &lt;# #&gt;
- C) &lt;* *&gt;
- D) &lt;% %&gt;

Answer: D) &lt;% %&gt;

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

74. Life cycle of a JSP page consists of the following steps.


- A) Translation, Compilation, Loading and Initialization, Request Handling, Destroy
- B) Initialization, Compilation, Execution, Destruction
- C) Translation, Execution, Loading, Initialization, Request Handling, Destroy
- D) Loading, Initialization, Request Handling, Execution, Destruction

Answer: A) Translation, Compilation, Loading and Initialization, Request Handling, Destroy

20 | P a g e
UINIT 5

75. The life cycle of the servlet is managed by ______________.


- A) Servlet Engine
- B) Web Container
- C) Servlet Container
- D) Application Server
Answer: C) Servlet Container

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

Answer: C) TRACE 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

Answer: C) PUT 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: C) GET method

84. Parameters are present in URL while using ____________ method.


- A) doPost()
- B) doGet()
- C) doPut()
- D) doRequest()

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

86. Servlet is _______ side scripting language.


- A) Server
- B) Client
- C) Both
- D) None
Answer: A) Server

87. Session management is possible using _______________.


- A) HttpSession
- B) HttpServletRequest
- C) ServletContext
- D) All of the mentioned

Answer: D) All of the mentioned

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

Answer: B) i-False, ii-True

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()

90. The GET and POST methods are specified in ____________.


- A) an HTML form
- B) a CSS file
- C) a JavaScript script
- D) an XML document
Answer: A) an HTML form

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

92. The HttpServlet class is defined in ___________ package.


- A) javax.servlet
- B) javax.servlet.http
- C) java.servlet
- D) java.servlet.http
Answer: B) javax.servlet.http

25 | P a g e
UINIT 5

93. The HttpServlet class supports ____________________________.


- A) only GET method
- B) only POST method
- C) both GET and POST methods
- D) neither GET nor POST methods

Answer: C) both GET and POST methods

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)

Answer: C) Java API for Servlets

26 | P a g e
UINIT 5

96. The javax.servlet.jsp package has two interfaces found in the following?
- A) JspPage &amp; JspServlet
- B) JspFile &amp; JspTag
- C) HttpJspPage &amp; JspTag
- D) JspWriter &amp; JspFactory

Answer: C) HttpJspPage &amp; JspTag

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()

Answer: B) init(), destroy(), jspInit(), jspDestroy()

98. The lifecycle of Servlet is managed by ______________.


- A) Servlet Engine
- B) Web Container
- C) Servlet Container
- D) Application Server

Answer: C) Servlet Container

27 | P a g e
UINIT 5

99. The major difference between servlet and CGI is:


- A) Servlets are process-based, and CGI is thread-based
- B) Servlets are thread-based, and CGI is process-based
- C) Both servlets and CGI are process-based
- D) Both servlets and CGI are thread-based

Answer: B) Servlets are thread-based, and CGI is process-based

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

Answer: B) 240 bytes

101. The parameters can be passed to an applet by using <PARAM> tag in the following way:
- A) &lt;PARAM NAME=parameter_name VALUE=parameter_value&gt;
- B) &lt;PARAMETER NAME=parameter_name VALUE=parameter_value&gt;
- C) &lt;PARAM NAME:parameter_name VALUE:parameter_value&gt;
- D) &lt;PARAMETER NAME:parameter_name VALUE:parameter_value&gt;

Answer: A) &lt;PARAM NAME=parameter_name VALUE=parameter_value&gt;

28 | P a g e
UINIT 5

102. The purpose of init() in the servlet life cycle is:


- A) Execution
- B) Destruction
- C) Initialization
- D) Compilation

Answer: C) Initialization

103. ServletConfig object Edit

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

A) Start, Run, Stop


B) Initialization, Processing, Termination
C) Initialization, Service, Destroy
D) Begin, Execute, Finish
Answer: C) Initialization, Service, Destroy

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

107. The__________________package contains a number of interfaces and classes that are


commonly used by servlet developers

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

112. Tomcat is a _____________ 5 N R 1 Web Server Edit

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

A) Filters are used for request modification


B) Filters are used for response modification
C) Filters can be used to intercept both requests and responses
D) All of these
Answer: D) All of these

115. What are the true sentences about Session-Id? 5 N R 1 All of these Edit

A) Session-Id is used to identify a user's session


B) Session-Id is stored in cookies or URL rewriting
C) Session-Id is used for session tracking
D) All of these
Answer: D) All of these

116. What is bytecode? 5 N R 1 Machine Independent code Edit

A) Code written in a high-level programming language


B) Code that is specific to a particular machine architecture
C) Code written in assembly language
D) Machine-independent code
Answer: D) Machine Independent code

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

119. What is the return type of getSession() method?

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.

121. What is the meaning of JAR? 5 N R 1 Java archived Edit

A) Java Archived Resource


B) Java Application Resource
C) Java Archived
D) Java Application
Answer: C) Java Archived

122. What does JSP stand for? 5 N R 1 Java Server Pages Edit

A) Java Server Programming


B) Java Server Page
C) Java Servlet Page
D) Java Script Page
Answer: B) Java Server Pages

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

127. Where do servlets run? 5 N R 1 on the server side Edit

A) On the client side


B) On the server side
C) On both client and server sides
D) On the database server
Answer: B) On the server side

128. Where does session data store? 5 N R 1 Session objects. Edit

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) Tag libraries provide a way to extend JSP functionality


B) Tag libraries encapsulate reusable code
C) Tag libraries are used to create custom tags
D) All of the above
Answer: D) All of the above

132. Which attribute is mandatory while creating a cookie 5 N R 1 Value 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

137. Which interface defines a getSession() method?

A) HttpServletRequest
B) HttpSession
C) ServletRequest
D) ServletContext
Answer: A) HttpServletRequest

138. Which is the interface of the following 5 N R 1 Servlet Edit

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
&lt;jsp:forward&gt; 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

A) init(), run(), end()


B) start(), execute(), stop()
C) init(), service(), destroy()
D) begin(), process(), finish()
Answer: C) init(), service(), destroy()

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()

146. Which method is called on every servlet request? 5 N R 1 service() Edit

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

151. Which method of HttpServletRequest is used to create a session?


- a) startSession()
- b) createSession()
- c) getSession()
- d) initiateSession()

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

154. Which methods are available in ServletContext interface?


- a) getAttribute(), getMimeType(String File), void Log(String s)
- b) getAttribute(), getMimeType(String file), log(String msg)
- c) setAttribute(), getMimeType(String type), log(String message)
- d) setAttribute(), getMime(String type), logMessage(String s)

Answer: b) getAttribute(), getMimeType(String file), log(String msg)

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()

156. Which of the following is not true for servlet?


- a) It is single-threaded.
- b) It is multi-threaded.
- c) It is both single-threaded and multi-threaded.
- d) It depends on the server configuration.

Answer: b) It is multi-threaded.

46 | P a g e
UINIT 5

157. Which of the following are class GenericServlet?


- a) HttpServlet
- b) GenericServlet
- c) Servlet
- d) Both a and b

Answer: d) Both a and b

158. Which of the following are examples of JSP directive?


- a) include
- b) import
- c) directive
- d) Both a and b

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

Answer: a) ServletContext, Servlet

47 | P a g e
UINIT 5

160. Which of the following are the session tracking techniques?


- a) URL rewriting, using session object, using cookies, using hidden fields
- b) Session rewriting, cookie tracking, form submission, hidden fields
- c) URL rewriting, form submission, cookie tracking, using session object
- d) Hidden fields, cookie tracking, using session object, URL rewriting

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) &lt;jsp:expression&gt;x&lt;/jsp:expression&gt;
- b) &lt;%=$x%&gt;
- c) &lt;%=x%&gt;
- d) &lt;jsp:output&gt;x&lt;/jsp:output&gt;

Answer: c) &lt;%=x%&gt;

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

Answer: d) All of the above.

164. Which of the following is legal JSP syntax to print the value of i?
- a) &lt;%int i = 1;%&gt;
- b) &lt;%= i %&gt;
- c) &lt;%out.println(i);%&gt;
- d) &lt;jsp:output&gt;i&lt;/jsp:output&gt;

Answer: b) &lt;%= i %&gt;

165. Which of the following is not a server-side technology?


- a) DHTML
- b) JavaServer Pages (JSP)
- c) ASP.NET
- d) PHP

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

169. Which of the following methods is used to destroy the session?


- a) destroy( )
- b) invalidate( )
- c) endSession( )
- d) closeSession( )

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

Answer: c) init(), service(), and destroy()

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

173. Which of these is not a method of GenericServlet?


- a) doGet
- b) service
- c) init
- d) destroy
Answer: a) doGet

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

Answer: a) 1, 3, 4 are correct

179. Which tag is used to declare one or more variables or methods?


- a) &lt;%!-----%&gt;
- b) &lt;%@ declaration %&gt;
- c) &lt;%@ page %&gt;
- d) &lt;%@ variable %&gt;

Answer: b) &lt;%@ declaration %&gt;

180. Why is JSP basically used today?


- a) To develop client-side scripts
- b) To develop server pages
- c) To create standalone applications
- d) To design graphical user interfaces

Answer: b) To develop server pages

53 | P a g e
UINIT 5

181. _____ is the first phase of servlet life cycle.


- a) initialization
- b) service
- c) destroy
- d) instantiation
Answer: a) initialization

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

184. __________ declares life cycle methods of servlet.


- a) Servlet
- b) Lifecycle
- c) ServletConfig
- d) ServletContext

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

186. ____________ is used to read data from a client request.


- a) ServletRequest
- b) HttpRequest
- c) HttpServletResponse
- d) HttpRequestBody
Answer: a) ServletRequest

187. ______________ method gives the current session.


- a) getCurrentSession()
- b) retrieveSession()
- c) getSession()
- d) obtainSession()
Answer: c) getSession()

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) &lt;%@ page ... %&gt;
- b) &lt;%@ attribute ... %&gt;
- c) &lt;%@ directive ... %&gt;
- d) &lt;%@ definition ... %&gt;

Answer: a) &lt;%@ page ... %&gt;

190. ________________ method executes at the end of the servlet life cycle.
- a) finish()
- b) complete()
- c) end()
- d) destroy()
Answer: d) destroy()

191. ________________ method is secure.


- a) doGet()
- b) doPost()
- c) service()
- d) doSecure()
Answer: b) doPost()

192. …………………. Life cycle method handles all client requests.


- a) start()
- b) process()
- c) execute()
- d) service()
Answer: d) service()

56 | P a g e
UINIT 5

193. import java.io.*;


import javax.servlet.*;
import javax.servlet.http.*;

public class HelloWorld extends HttpServlet {


public void doGet(_______________, ____________________) throws ServletException,
IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<HTML>");
out.println("<HEAD><TITLE>Hello World</TITLE></HEAD>");
out.println("<BODY>");
out.println("<H1>Hello World</H1>");
out.println("</BODY></HTML>");
}
}
What are the parameters for doGet()?
- a) (HttpServletRequest req, HttpServletResponse res)
- b) (HttpRequest req, HttpResponse res)
- c) (ServletRequest req, ServletResponse res)
- d) (Request req, Response res)

Answer: a) (HttpServletRequest req, HttpServletResponse res)

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.*;

public class ColorGetServlet extends HttpServlet {


public void ******(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
String color = request.getParameter("color");
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<B>The selected color is: ");
pw.println(color);
pw.close();
}
}
- a) doPost()
- b) doPostMethod()
- c) processPost()
- d) handlePost()

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.*;

public class PostParametersServlet extends GenericServlet {


public void service(ServletRequest request, ServletResponse response) throws ServletException,
IOException {
// Get print writer.
PrintWriter pw = response.getWriter();
// Get enumeration of parameter names.
Enumeration e = request.getParameterNames();
// Display parameter names and values.
while (e.hasMoreElements()) {
String pname = 5 N A 2 request.getParameterName(pname) Edit
(String) e.nextElement();
pw.print(pname + " = ");
String pvalue = *******;
pw.println(pvalue);
}
pw.close();
}
}
- a) request.getParameterValue(pname)
- b) request.getParameter(pname)
- c) request.getParameterName(pname)
- d) request.getValue(pname)

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.*;

public class p172 extends HttpServlet {


public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
PrintWriter z;
z = new PrintWriter(response.getOutputStream());
String x = request.getParameter("data");
String y = request.getParameter("data");
String a = request.getParameter("data");
String b = request.getParameter("data");
Cookie c = new Cookie("MyCookie", x);
response.addCookie(c);
******* z.println("<b>mycookie has been set to");
z.println(x);
z.close();
}
}
- a) z.setContentType("text/html");
- b) response.setContentType("text/html");
- c) z.setResponseType("text/html");
- d) response.setResponseType("text/html");

Answer: b) response.setContentType("text/html");

60 | P a g e
UINIT 5

197. _________ contains classes and interfaces required to build servlets.


- a) java.servlet
- b) javax.servlet
- c) servlet.api
- d) javax.api.servlet

Answer: b) javax.servlet

198. <form action="/handler">


<!-- form tags here -->
</form>
The URL pattern /handler is mapped to an HTTP servlet. Which HttpServlet service method will
the web container call in response to this form submit?
- a) doGet()
- b) doPost()
- c) service()
- d) handle()

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

You might also like