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!

Q31

Q31 A controller method is not being called even though the URL mapping is correct. What could be the issue?

A

DispatcherServlet is missing

B

Incorrect HTTP method used in the request

C

Database connection issue

D

Application is not deployed properly

Q32

Q32 What is the purpose of the @RequestMapping annotation in Spring MVC?

A

To map HTTP requests to controller methods

B

To define beans in the Spring container

C

To handle database transactions

D

To manage view resolution

Q33

Q33 Which attribute of @RequestMapping is used to specify the HTTP method?

A

value

B

method

C

path

D

produces

Q34

Q34 What happens if a request does not match any @RequestMapping method?

A

It is ignored

B

Spring MVC returns a 404 error

C

Spring MVC redirects to the default controller

D

Spring MVC executes the first controller method

Q35

Q35 How do you define multiple URL mappings for a single controller method?

A

Use multiple @RequestMapping annotations

B

Provide multiple values inside a single @RequestMapping annotation

C

Define separate controller methods

D

Use a wildcard (*) in URL mapping

Q36

Q36 What is the difference between @RequestMapping and @GetMapping?

A

@GetMapping is specific to GET requests, while @RequestMapping supports multiple HTTP methods

B

Both are identical

C

@RequestMapping is specific to GET requests, while @GetMapping supports multiple HTTP methods

D

@GetMapping is used for form handling only

Q37

Q37 Which annotation is used to map dynamic path variables in Spring MVC?

A

@RequestParam

B

@PathVariable

C

@ModelAttribute

D

@RequestBody

Q38

Q38 How do you define a method that handles HTTP POST requests?

A

@PostMapping("/submit")

B

@RequestMapping(value="/submit", method=RequestMethod.POST)

C

Both A and B

D

@GetMapping("/submit")

Q39

Q39 How do you pass a query parameter in a GET request?

A

/users?id=1

B

/users/1

C

/users?id==1

D

/users?id-1

Q40

Q40 What is the correct way to extract query parameters in Spring MVC?

A

@PathVariable("id") int id

B

@RequestParam("id") int id

C

@ModelAttribute("id") int id

D

@RequestBody int id

Q41

Q41 A request is returning a 405 (Method Not Allowed) error. What is the likely cause?

A

The URL mapping is incorrect

B

The request is using an unsupported HTTP method

C

The database is down

D

The controller is missing

Q42

Q42 A controller method using @RequestMapping is not being invoked. What could be the issue?

A

The method is private

B

The URL pattern does not match

C

The controller is not annotated with @RestController

D

All of the above

Q43

Q43 A developer needs to handle both GET and POST requests in the same method. How can this be achieved?

A

Use two different methods

B

Use multiple @RequestMapping annotations with different methods

C

Use @RequestMapping with method={RequestMethod.GET, RequestMethod.POST}

D

It is not possible

Q44

Q44 What is the primary role of the Model in the MVC pattern?

A

To handle user interactions

B

To store and manage data

C

To control the view rendering

D

To map HTTP requests to methods

Q45

Q45 Which component in MVC is responsible for displaying data to the user?

A

Model

B

View

C

Controller

D

DispatcherServlet

Q46

Q46 Which component in MVC handles user inputs and updates the Model?

A

Model

B

View

C

Controller

D

Service

Q47

Q47 Which of the following best describes the MVC pattern?

A

A software pattern that separates concerns

B

A database management technique

C

A cloud computing model

D

A UI rendering framework

Q48

Q48 What is the main benefit of using the MVC pattern in Spring applications?

A

It allows for better scalability and maintenance

B

It improves database performance

C

It makes the application load faster

D

It eliminates the need for front-end code

Q49

Q49 In Spring MVC, how does the Controller communicate with the View?

A

By modifying the database

B

By returning a View object

C

By using Model and ViewResolver

D

By calling JavaScript functions

Q50

Q50 Which method is commonly used in a controller to add data to the Model?

A

setModel()

B

addAttribute()

C

setAttribute()

D

setView()

Q51

Q51 How do you return a View name from a Spring MVC controller method?

A

return "index.jsp";

B

return new ModelAndView("index");

C

return "index";

D

return View("index");

Q52

Q52 Which class in Spring MVC is responsible for resolving the logical view name to an actual view?

A

ModelAndView

B

ViewResolver

C

DispatcherServlet

D

RequestMapping

Q53

Q53 A developer is facing an issue where the model attributes are not available in the View. What could be the reason?

A

The controller is missing @RequestMapping

B

The model attributes were not added using addAttribute()

C

The database is not connected

D

The view file is missing

Q54

Q54 A Spring MVC application is rendering a blank page instead of the expected View. What could be the issue?

A

The ViewResolver is not configured correctly

B

The Model is empty

C

The Controller does not return a View name

D

The View file is missing

Q55

Q55 A developer is receiving a '404 Not Found' error when trying to access a View in Spring MVC. What could be the cause?

A

Incorrect View name returned from Controller

B

ViewResolver is not configured properly

C

The requested View file does not exist

D

Incorrect request mapping

Q56

Q56 Which annotation in Spring MVC is used to bind form data to a model object?

A

@RequestParam

B

@ModelAttribute

C

@RequestBody

D

@PathVariable

Q57

Q57 What is the primary advantage of using @ModelAttribute in Spring MVC?

A

It simplifies form data binding

B

It improves database transactions

C

It enhances security

D

It manages session attributes

Q58

Q58 Which Spring MVC annotation is used to retrieve query parameters from a request?

A

@PathVariable

B

@RequestParam

C

@ModelAttribute

D

@RequestMapping

Q59

Q59 How does Spring MVC handle form validation?

A

Using custom JavaScript functions

B

Using @Valid and BindingResult

C

Using @Autowired

D

Using @PathVariable

Q60

Q60 Which object in Spring MVC is used to store validation errors from form submissions?

A

Model

B

BindingResult

C

Session

D

ResponseEntity

ad verticalad vertical
ad