Showing posts with label MVC. Show all posts
Showing posts with label MVC. Show all posts

UpWork (oDesk) & Elance Spring MVC Test Question & Answers

17:47 Add Comment
UpWork (oDesk) & Elance Spring MVC Test Question & Answers are really very important to pass UpWork & Elance test. You will get top score at this skill test exam. If you found any problem or wrong answer please inform me via contact or comments. We will try to solve it in short. This test is extremely valuable to acquire knowledge of Spring MVC. Lets Start test.


Ques : In an annotation-based Spring MVC controller, which of the following are valid ways to set cache headers for a specific path?
Ans  :  Ensuring the instance of "AnnotationMethodHandlerAdapter" does not have the    "cacheSeconds" property set, and adding an instance of "WebContentInterceptor".
       Adding "final HttpServletResponse response" as a parameter, then setting the header "Cache-Control" to "all-cache".
       Using a Handler Interceptor and using the "postHandle" method provided by it.

Ques : Which of the following are valid sets of constructor arguments for the ModelAndView class? (Select all correct answers.)
Ans  :  String viewName
        String viewName, Map model

Ques :  Which of the following are possible validation methods for user input in Spring MVC?
Ans  :  Annotation validation
        Programmatic validation

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

Ques : Which of the following dependency injection (DI) methodologies are available in Spring MVC?
Ans  : Constructor-based dependency injection
       Setter-based dependency injection

Ques : Which of the following interfaces can be implemented to interact with a container's management of the bean lifecycle?
Ans  : InitializingBean
       DisposableBean

Ques : Select all authentication methods that are supported by Spring Security by default:
Ans  : Basic Authentication
       Digest Access Authentication

Ques : True or false: a factory class can hold more than one factory method.
Ans  : True

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

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

Ques : 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);
    ...
}
Ans  :  It retrieves the partial path value (after "**") before the @RequestMapping and @PathVariable values have been parsed.

Ques : Which of the following can be used to serve static resources while still using DispatchServlet at the site's root?
Ans  :

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

Ques : Which of the following annotations are supported by classes with the @Bean annotation?
Ans  :  @PostConstruct

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

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

Ques : Given the following method:

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

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

Ques : Which of the following classes provides built-in pagination functionality in SpringMVC?
Ans  : PagedListHolder

Ques : 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?
Ans  : The attribute name-value pair will be included in the URL, regardless of the use of @ModelAttribute in the controller.

Ques : Which of the following is true about the use of in a servlet?
Ans  :   activates many different annotations in beans, whether they are defined in XML or through component scanning.

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

Ques : Which of the following statements is true about the @RequestMapping annotation?
Ans  : It supports ant-style paths.

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

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

Ques : How can an HTTP 404 status code be returned from a Spring MVC Controller?
Ans  : Having the method accept HttpServletResponse as a parameter, so that setStatus(404) can be called on it.

Ques : Which of the following is the default bean scope in Spring MVC?
Ans  : singleton

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

Ques : Which of the following statements is correct?
Ans  : doesn't declare its own handler mapping

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

Ques : Which of the following code samples will correctly return an image in @ResponseBody from a byte[] of image data?
Ans  : @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); }

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

Ques : Which of the following is not a built-in Spring MVC bean scope?
Ans  : local session

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

Ques : 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.
Ans  : class

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

Ques : Fill in the blank:
In Spring's XML-based configuration, the _______ attribute of the element specifies a property or constructor argument as a string representation.
Ans  : name

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

Thanks for watching this test Question & Answers. Please don't forget to leave a comment about this post. You can also find some more effective test question & answers, information, techniques, technology news, tutorials, online earning information, recent news, results, job news, job exam results, admission details & another related services on the following sites below. Happy Working!
News For Todays ARSBD UpWorkElanceTests ARSBD-JOBS DesignerTab UpLance