Spring MVC MCQ Banner

Spring MVC Multiple Choice Questions (MCQs) and Answers

Master Spring MVC with Practice MCQs. Explore our curated collection of Multiple Choice Questions. Ideal for placement and interview preparation, our questions range from basic to advanced, ensuring comprehensive coverage of Spring MVC concepts. Begin your placement preparation journey now!

Q1

Q1 What is the primary purpose of Spring MVC in a web application?

A

To manage database transactions

B

To handle client-side JavaScript code

C

To implement the Model-View-Controller pattern for web applications

D

To manage dependency injection in an application

Q2

Q2 Which module of the Spring Framework provides support for Spring MVC?

A

Spring JDBC

B

Spring ORM

C

Spring Web

D

Spring Security

Q3

Q3 Which design pattern does Spring MVC follow?

A

Singleton

B

Factory

C

Model-View-Controller

D

Decorator

Q4

Q4 Which of the following is NOT a key component of Spring MVC?

A

DispatcherServlet

B

ModelAndView

C

SessionFactory

D

ViewResolver

Q5

Q5 What is the role of DispatcherServlet in Spring MVC?

A

It handles database transactions

B

It dispatches requests to appropriate controllers

C

It is responsible for managing sessions

D

It compiles Java code into bytecode

Q6

Q6 Which interface does DispatcherServlet implement?

A

Servlet

B

HttpServlet

C

GenericServlet

D

ServletContextListener

Q7

Q7 In Spring MVC, what is the default URL mapping of DispatcherServlet?

A

/

B

/dispatcher/

C

/.mvc

D

/*

Q8

Q8 Which annotation in Spring MVC is used to define a controller class?

A

@Service

B

@RestController

C

@Controller

D

@Component

Q9

Q9 A Spring MVC application is returning a '404 Not Found' error when accessing a URL. What is the most likely cause?

A

The controller method handling the request is missing the @RequestMapping annotation.

B

The database connection is misconfigured.

C

The @Service annotation is missing in the service layer.

D

The application is not running on the correct Java version.

Q10

Q10 What is the role of the DispatcherServlet in Spring MVC?

A

To manage the database connections

B

To act as the front controller

C

To perform dependency injection

D

To handle authentication

Q11

Q11 Which component in Spring MVC is responsible for resolving views?

A

ModelAndView

B

ViewResolver

C

ViewHandler

D

ResponseMapper

Q12

Q12 In Spring MVC, where is the request first received?

A

Model

B

ViewResolver

C

Controller

D

DispatcherServlet

Q13

Q13 Which component in Spring MVC handles request mapping?

A

DispatcherServlet

B

HandlerMapping

C

ViewResolver

D

Model

Q14

Q14 Which component in Spring MVC handles user inputs and binds them to objects?

A

HandlerMapping

B

Model

C

DataBinder

D

ViewResolver

Q15

Q15 What happens after DispatcherServlet receives a request in Spring MVC?

A

It directly renders the view

B

It routes the request to the appropriate controller using HandlerMapping

C

It executes the database query

D

It validates the request headers

Q16

Q16 What is the main function of HandlerAdapter in Spring MVC?

A

To handle HTTP requests

B

To execute the appropriate controller method

C

To perform security validation

D

To manage view resolution

Q17

Q17 Which of the following best describes the Model in Spring MVC?

A

A template engine

B

A way to pass data between the controller and the view

C

A database entity

D

A part of the front-end framework

Q18

Q18 Which method in Spring MVC is typically used to add model attributes?

A

setAttribute()

B

addObject()

C

addAttribute()

D

setModel()

Q19

Q19 A developer is facing an issue where the correct view is not being resolved in a Spring MVC application. What could be the most likely reason?

A

Incorrect HandlerMapping configuration

B

ViewResolver is not properly configured

C

DispatcherServlet is missing

D

Controller class is missing

Q20

Q20 What is the main responsibility of a controller in Spring MVC?

A

Handling business logic

B

Managing database transactions

C

Handling HTTP requests and returning responses

D

Rendering views

Q21

Q21 Which annotation is used to handle form submissions in Spring MVC?

A

@ModelAttribute

B

@RequestBody

C

@RequestParam

D

@ResponseBody

Q22

Q22 Which annotation is used to handle HTTP GET requests in a Spring MVC controller?

A

@RequestMapping

B

@GetMapping

C

@PostMapping

D

@PutMapping

Q23

Q23 Which return type is commonly used in a Spring MVC controller method to return a view?

A

void

B

ModelAndView

C

HttpServletResponse

D

String

Q24

Q24 What is the purpose of the @RequestParam annotation in Spring MVC?

A

To inject a service into the controller

B

To map request parameters to method arguments

C

To handle session management

D

To return a JSON response

Q25

Q25 Which annotation is used to handle exceptions in a Spring MVC controller?

A

@ErrorHandler

B

@ExceptionHandler

C

@ErrorController

D

@RestController

Q26

Q26 What is the default scope of a Spring MVC controller?

A

Prototype

B

Session

C

Singleton

D

Request

Q27

Q27 How do you define a request mapping for the URL '/home' in a Spring MVC controller?

A

@RequestMapping("/home")

B

@RequestMapping(path="/home")

C

@GetMapping("/home")

D

All of the above

Q28

Q28 How do you pass data from a Spring MVC controller to a view using the Model?

A

model.set("key", value)

B

model.add("key", value)

C

model.addAttribute("key", value)

D

model.put("key", value)

Q29

Q29 A developer is getting a 400 Bad Request error when submitting a form in Spring MVC. What is the most likely cause?

A

Incorrect database query

B

Missing @RequestParam annotation

C

Incorrect model binding

D

Application is not running

Q30

Q30 A Spring MVC application is returning a '500 Internal Server Error'. What could be the most probable cause?

A

A missing controller class

B

An exception occurring in the controller

C

A missing DispatcherServlet

D

A misconfigured web.xml

ad verticalad vertical
ad