Java Spring Multiple Choice Questions & Answers (MCQs) on “Views Mapping and Handling”.
1. Interface for Dispatcher Servlet to auto detect view resolver beans.
a) localeResolver
b) tiles
c) ViewResolver
d) none of the mentioned
Answer: c
Clarification: Spring MVC comes with several ViewResolver implementations for you to resolve views using different strategies.
2. ViewResolver which maps each view name tol an application’s directory.
a) InternalViewResolver
b) InternalResourceViewResolver
c) InternalResolver
d) None of the mentioned
Answer: b
Clarification: The view resolver InternalResourceViewResolver maps each view name to an application’s directory by means of a prefix and a suffix declaration.
3. InternalResourceViewResolver resolves view names into view objects of type.
a) JstlView
b) Jst Library
c) View
d) None of the mentioned
Answer: a
Clarification: By default, InternalResourceViewResolver resolves view names into view objects of type JstlView if the JSTL library (i.e., jstl.jar) is present in the classpath.
4. By default, XmlViewResolver loads view beans from /WEB-INF/views.xml which is final.
a) True
b) False
Answer: b
Clarification: This location can be overridden through the location property.
5. View beans from a resource bundle is loaded by.
a) ResourceBundleViewResolver
b) ResourceBundleView
c) ResourceViewResolver
d) None of the mentioned
Answer: a
Clarification: ResourceBundleViewResolver loads view beans from a resource bundle in the classpath root.
6. Views that can’t be resolved by InternalResourceViewResolver.
a) redirect
b) redirect:prefix
c) redirect:suffix
d) all of the mentioned
Answer: a
Clarification: Now the resource bundle views.properties should only contain the views that can’t be resolved by InternalResourceViewResolver (e.g., the redirect views).
7. Properties used to determine the correct content and type for a certain web requests.
a) The URL extension provided in a request
b) The HTTP Accept header
c) All of the mentioned
d) None of the mentioned
Answer: c
Clarification: When a request is received for a web application, it contains a series of properties that allow the processing framework, in this case Spring MVC, to determine the correct content and type to return to the requesting party.
8. Inspection of header is done by which of the following.
a) InternalViewResolver
b) ContentNegotiatingViewResolver
c) ContentNegotiating
d) InternalResolver
Answer: b
Clarification: Inspecting HTTP Accept headers in a controller can be a messy process. So Spring MVC supports the inspection of headers through the ContentNegotiatingViewResolver.
9. ContentNegotiatingViewResolver resolver configuration sets up the resolver to have the highest priority among all resolvers.
a) True
b) False
Answer: a
Clarification: It’s necessary to make the content negotiating resolver work.
10. The ContentNegotiatingViewResolver resolver first determines the media type for a request based on which of the following criteria?
a) It checks a request path extension
b) If a request path has an extension but no match can be found in the default mediaTypes section of the ContentNegotiatingViewResolver bean
c) If no extension is present in a request path, the HTTP Accept header of the request is used
d) All of the mentioned
Answer: d
Clarification: It checks a request path extension (e.g., .html, .xml, or .pdf) against the default
media types (e.g., text/html) specified in the mediaTypes section of the
ContentNegotiatingViewResolver bean.
If a request path has an extension but no match can be found in the default
mediaTypes section of the ContentNegotiatingViewResolver bean, an attempt is
made to determine an extension’s media type using FileTypeMap belonging to Java
Activation Framework.
If no extension is present in a request path, the HTTP Accept header of the request
is used.
11. In a Spring MVC application, you can register one or more exception resolver beans in the web application context to resolve uncaught exceptions.
a) True
b) False
Answer: a
Clarification: These beans have to implement the HandlerExceptionResolver interface for DispatcherServlet to auto-detect them.
12. To configure the exception mappings in the web application context.
a) SimpleMappingExceptionResolver
b) ExceptionResolver
c) ExceptionViewResolver
d) None of the mentioned
Answer: a
Clarification: Spring MVC comes with the exception resolver SimpleMappingExceptionResolver for you to configure the exception mappings in the web application context.
13. Annotation which allows a controller’s field to be assigned using Spring Expression Language(SpEL)
a) @Value
b) @After
c) @Default
d) @None
Answer: a
Clarification: You can use the @Value annotation along with SpEL to query beans present in an application’s context and extract values to help you initialize controller fields.
14. SpEL statements are recognizable.
a) True
b) False
Answer: a
Clarification: They use a notation in the form “#{ SpEL statement }”.
15. Tag, used to define a location in which to place errors in case a form.
a) form
b) form:GET
c) form:POST
d) form:errors
Answer: d
Clarification: You can find the form:errors tag, used to define a location in which to place errors in case a form does not meet the rules set forth by a controller.