Upwork Test Answers: Get all the correct answers of most recent and possible Upwork Tests A to Z (Updated on Jan, 2016)
Cover Letter Templates: These cover letter samples are not only for Upwork job, but also you will have some idea about your real life job
 
Freelance Profile Overviews: Different Profile samples and overviews of experts, advanced and intermediate level freelancers
For Newbie of Upwork: Upwork Help - How to apply for a job in Upwork with 10 most important articles about Upwork

A to Z View - All Upwork Test Answers

Spring MVC Test Answers (new)

Spring MVC Test is one of the Database category test of Upwork. It will help you to get jobs in Upwork, Here you will find most recent Upwork test questions and correct answers of Upwork Spring MVC Test.

Search your desired answers of Upwork Spring MVC Test questions by pressing Ctrl + F button
--------------------------------------------------------------------------------------------------------------------------


1. Which of the following code samples will get the ServletContext inside an Interceptor?
 Answers: • @Autowired ServletContext context; or • request.getSession().getServletContext();

 2. How can an HTTP 404 status code be returned from a Spring MVC Controller?
 Answers: • Throwing a ResourceNotFoundException declared with the @ResponseStatus annotation. or • Having the method accept HttpServletResponse as a parameter, so that setStatus(404) can be called on it.

 3. Which of the following interfaces can be implemented to interact with a container's management of the bean lifecycle?
 Answers: • InitializingBean or • DisposableBean

 4. Which of the following can be used to serve static resources while still using DispatchServlet at the site's root?
 Answers: • <mvc:resources/> or • <mvc:default-servlet-handler/>

 5. Which of the following code samples will correctly return an image in @ResponseBody from a byte[] of image data?
 Answers: • @RequestMapping("/photo") public ResponseEntity<byte[]> testphoto() throws IOException { InputStream in = servletContext.getResourceAsStream("/images/no_image.jpg"); final HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.IMAGE_PNG); return new ResponseEntity<byte[]>(IOUtils.toByteArray(in), headers, HttpStatus.CREATED); } or
 • @ResponseBody @RequestMapping("/photo", method = RequestMethod.GET, produces = MediaType.IMAGE_JPEG_VALUE) public byte[] testphoto() throws IOException { InputStream in = servletContext.getResourceAsStream("/images/no_image.jpg"); return IOUtils.toByteArray(in); }

 6. Which of the following annotations are supported by classes with the @Bean annotation?
 Answers: • @PostConstruct or • @PreDestroy

 7. Which of the following statements is false?
 Answers: • By default, a transaction is only marked for rollback in the case of runtime unchecked exceptions.

 8. Which of the following statements is true about the HandlerExceptionResolver class?
 Answers: • DefaultHandlerExceptionResolver converts standard Spring exceptions and converts them to HTTP Status Codes.

 9. Which of the following statements is true about method arguments that have an @ModelAttribute annotation?
 Answers: • Model attributes have to be explicitly added when using @ModelAttribute.

 10. Given the following method:

 @RequestMapping(method=RequestMethod.GET, value="/fooBar")
 public ResponseEntity<String> fooBar2() {
 String json = "jsonResponse";
 HttpHeaders responseHeaders = new HttpHeaders();
 responseHeaders.setContentType(MediaType.APPLICATION_JSON);
 return new ResponseEntity<String>(json, responseHeaders, HttpStatus.CREATED);
 }

 Which of the following statements is correct?
 Answers: • It returns a JSON String and sets the mimetype to text/javascript.

 11. Which of the following classes provides built-in pagination functionality in SpringMVC?
 Answers: • PagedListHolder

 12. Given the method below:

 @RequestMapping(value = "/foo", method = RequestMethod.GET)
 public final String foo(HttpServletRequest request, BindingResult bindResult, ModelMap model) {
 model.addAttribute("abc", 123);
 return "foo";
 }

 When the view is displayed in the browser, it's URL is "http://mydomain/foo?abc=123".

 Which of the following statements is true?
 Answers: • The attribute name-value pair will be included in the URL, regardless of the use of @ModelAttribute in the controller.

 13. Which of the following is true about the use of <context:annotation-config /> in a servlet?
 Answers: • <context:annotation-config> activates many different annotations in beans, whether they are defined in XML or through component scanning.

 14. Which of the following are valid sets of constructor arguments for the ModelAndView class? (Select all correct answers.)
 Answers: • String viewName, Map<String,?> model

 15. Which of the following are possible validation methods for user input in Spring MVC?
 Answers: • Annotation validation

 16. Fill in the blank:
 The _______ enables the use of the bean element’s attributes, instead of nested <property/> elements, to describe property values and/or collaborating beans.
 Answers: • p-namespace

 17. Which of the following statements is true about the @RequestMapping annotation?
 Answers: • It has a single String parameter.

 18. Which of the following statements is true for the configuration of the Spring handler adapter(s) in a Spring MVC application context?
 Answers: • If at least one request handler adapter is defined the context files, Spring will not create the default adapters.

 19. What does the following code do?

 @RequestMapping("/{id}/**")
 public void foo(@PathVariable("id") int id, HttpServletRequest request) {
 String restOfTheUrl = (String) request.getAttribute(
 HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
 ...
 }
 Answers: • It retrieves the partial path value (after "**") before the @RequestMapping and @PathVariable values have been parsed.

 20. Which of the following statements is true about the HandlerInterceptor interface?
 Answers: • It allows exchanging the request and response objects that are handed down the execution chain.

 21. Which of the following dependency injection (DI) methodologies are available in Spring MVC?
 Answers: • Constructor-based dependency injection

 22. Which of the following is the default bean scope in Spring MVC?
 Answers: • singleton

 23. True or false: a factory class can hold more than one factory method.
 Answers: • True

 24. Which of the following enables custom qualifier annotation types to be registered even if they are not annotated with Spring’s @Qualifier annotation?
 Answers: • CustomAutowireConfigurer

 25. Which of the following statements is correct?
 Answers: • <mvc:resources> declares only DefaultAnnotationHandlerMapping by default.

 26. Which of the following statements is true about the @RequestParam annotation?
 Answers: • It indicates that a method parameter should be bound to a web request parameter.

 27. Select all authentication methods that are supported by Spring Security by default:
 Answers: • Digest Access Authentication

 28. In an annotation-based Spring MVC controller, which of the following are valid ways to set cache headers for a specific path?
 Answers: • Ensuring the instance of "AnnotationMethodHandlerAdapter" does not have the "cacheSeconds" property set, and adding an instance of "WebContentInterceptor".

 29. What is the difference between the @Repository and the @Controller annotations in Spring?
 Answers: • "@Repository" is used as a stereotype for the persistence layer, while "@Controller" is used as a stereotype for the presentation layer.

 30. Which of the following statements are correct, with respect to using the @PreAuthorize annotation in Spring controller methods?
 Answers: • @PreAuthorize works with Spring controller methods.

 31. Which of the following is not a built-in Spring MVC bean scope?
 Answers: • local session

 32. Fill in the blank: _______ is a class-level annotation indicating that an object is a source of bean definitions.
 Answers: • @Configuration

 33. Regarding the @Resource annotation, which of the following statements is false?
 Answers: • If no name attribute is specified, the default name is derived from the field name or setter method.

 34. Fill in the blank:
 When defining a bean that is created with a static factory method, the ______ attribute is used to specify the class containing the static factory method.
 Answers: • factory-class

 35. Which of the following statements is true about the @ModelAttribute annotation?
 Answers: • It can be used to expose reference data to a web view.

 36. Fill in the blank:
 In Spring's XML-based configuration, the _______ attribute of the <property/> element specifies a property or constructor argument as a string representation.
 Answers: • name

 37. Which of the following statements is/are true about autowiring in Spring?
 Answers: • Fields are injected after the construction of a bean.

 38. Regarding dependency resolution, which of the following statements is false?
 Answers: • Configuration metadata can only be specified via XML or annotations.