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!

Q61

Q61 Which configuration is required for enabling Spring MVC's form validation?

A

Enable component scanning

B

Add a Validator bean and use @Valid

C

Use @Autowired in the Controller

D

Define a custom ViewResolver

Q62

Q62 Which method is used to bind form attributes in Spring MVC?

A

model.addObject()

B

model.addAttribute()

C

request.getAttribute()

D

response.setAttribute()

Q63

Q63 How do you specify a default value for a request parameter in @RequestParam?

A

@RequestParam("id", defaultValue="1")

B

@RequestParam(value="id", default="1")

C

@RequestParam(value="id", required=false)

D

@RequestParam("id")

Q64

Q64 How can you handle multiple form submissions in Spring MVC?

A

Using multiple controller methods with @RequestMapping

B

Using @SessionAttributes

C

Using a single method with @ModelAttribute

D

Using @Component annotation

Q65

Q65 A form submission in Spring MVC is not binding data to the model. What is the likely reason?

A

The controller method does not have @ModelAttribute

B

The form action URL is incorrect

C

The view is missing a submit button

D

The model object is not annotated with @Entity

Q66

Q66 A required request parameter is missing, causing an error. How can this be handled?

A

Use a try-catch block

B

Use @RequestParam with required=false

C

Redirect to an error page

D

Use @RequestBody instead

Q67

Q67 A developer is facing an issue where form validation is not working in Spring MVC. What could be the reason?

A

The controller method is missing @Valid

B

The form has incorrect input types

C

The form is missing a submit button

D

The application is using an outdated Spring version

Q68

Q68 Which of the following is a view technology supported by Spring MVC?

A

JSP

B

Thymeleaf

C

Freemarker

D

All of these

Q69

Q69 What is the role of a ViewResolver in Spring MVC?

A

To map logical view names to actual view templates

B

To handle HTTP requests

C

To validate user input

D

To manage session attributes

Q70

Q70 Which statement about JSP and Thymeleaf is correct?

A

JSP is an HTML-based template engine

B

Thymeleaf is a Spring-integrated template engine

C

JSP requires a servlet container to run

D

Both B and C

Q71

Q71 Which is a major advantage of using Thymeleaf over JSP in Spring MVC?

A

Thymeleaf can be used as a standalone template engine

B

Thymeleaf does not require a servlet container

C

JSP has better integration with Spring MVC

D

JSP has more security features

Q72

Q72 Which of the following is NOT a valid way to pass data from a Spring MVC controller to a JSP view?

A

Using Model object

B

Using HttpSession

C

Using JavaScript

D

Using ModelAndView

Q73

Q73 Which expression is used in JSP to display the value of a request attribute?

A

${requestScope.value}

B

${sessionScope.value}

C

${value}

D

${param.value}

Q74

Q74 How do you reference a model attribute in a Thymeleaf template?

A

${model.attribute}

B

#{attribute}

C

${attribute}

D

@{attribute}

Q75

Q75 How can you create a hyperlink in a Thymeleaf template that dynamically maps to a Spring MVC controller?

A

<a href='/home'>Home</a>

B

<a th:href='@{/home}'>Home</a>

C

<a th:ref='/home'>Home</a>

D

<a link='home'>Home</a>

Q76

Q76 Which tag is used in JSP to include another JSP file dynamically?

A

jsp:import

B

jsp:include

C

jsp:forward

D

jsp:invoke

Q77

Q77 A JSP page is not rendering correctly, showing raw EL expressions like ${attribute}. What could be the issue?

A

The EL syntax is incorrect

B

The view resolver is misconfigured

C

Expression Language (EL) is disabled

D

The controller is missing @RequestMapping

Q78

Q78 A Thymeleaf template is not displaying dynamic data. What could be the reason?

A

The controller is not returning a Model attribute

B

The view resolver is not configured

C

The template file is missing

D

The application is not deployed correctly

Q79

Q79 A developer is getting a 'Template not found' error in Thymeleaf. What is the most likely cause?

A

The template path is incorrect

B

The model attribute is missing

C

Thymeleaf dependency is missing

D

The database connection is incorrect

Q80

Q80 Which annotation is used in Spring MVC to handle exceptions at the controller level?

A

@RequestMapping

B

@ExceptionHandler

C

@ControllerAdvice

D

@RestController

Q81

Q81 What is the purpose of @ControllerAdvice in Spring MVC?

A

To provide global exception handling for controllers

B

To handle security authentication

C

To resolve views

D

To inject dependencies

Q82

Q82 Which interface in Spring MVC can be used for customized exception handling?

A

HandlerInterceptor

B

HandlerExceptionResolver

C

ControllerAdvice

D

DispatcherServlet

Q83

Q83 What happens when an exception occurs in a Spring MVC controller that is not explicitly handled?

A

The request is forwarded to the default error page

B

Spring MVC returns a 500 error response

C

The request is silently ignored

D

The request is retried automatically

Q84

Q84 Which of the following is NOT a recommended approach for handling exceptions in Spring MVC?

A

Using @ExceptionHandler methods

B

Defining a global exception handler with @ControllerAdvice

C

Throwing unchecked exceptions without handling

D

Implementing HandlerExceptionResolver

Q85

Q85 How do you define an exception handler for NullPointerException in a Spring MVC controller?

A

@ExceptionHandler(NullPointerException.class)

B

@ControllerAdvice(NullPointerException.class)

C

@ErrorHandler(NullPointerException.class)

D

@HandleException(NullPointerException.class)

Q86

Q86 How can you return a custom error response from an exception handler in Spring MVC?

A

Returning a String as a view name

B

Returning a ResponseEntity object

C

Throwing the exception again

D

Returning null

Q87

Q87 Which method in HandlerExceptionResolver is used to resolve exceptions?

A

resolveException()

B

handleException()

C

processException()

D

mapException

Q88

Q88 How can you configure a custom error page in Spring MVC?

A

Using @ExceptionHandler

B

Using @ErrorPage

C

Defining an entry in web.xml

D

Creating a Controller with an error endpoint

Q89

Q89 A Spring MVC application is showing a generic 500 error page instead of a custom error message. What could be the issue?

A

The controller does not have @ExceptionHandler

B

@ControllerAdvice is missing

C

The custom error page is not configured properly

D

The database is down

Q90

Q90 A controller-specific exception handler is not catching exceptions. What could be the issue?

A

The method is missing @ExceptionHandler

B

The exception type does not match

C

The method is private

D

All of the above

ad verticalad vertical
ad