Chapter XV interceptor - Exercise answer

Course description: "Framework technology" is software engineering core curriculum is the professional elective, is a Java application development courses, student employment is the main direction of this profession.
Description: The frame design exercise answers other chapters also in this "spring frame design" column.

First, fill in the blank

  1. Spring MVC order of execution in a single interceptor, after the request has been handled] [DispatcherServlet will be performed afterCompletion () method.
  2. Spring MVC The interceptor (Interceptor) or similar filters [Filter] in Servlet, it is mainly for intercepting a user request and processed accordingly.
  3. If you do not log on to the system and direct access to the main page, the interceptor will intercept the request and forwarded to the login page [].
  4. When there are a plurality of interceptors simultaneously, they The preHandle [()] method executes the order configured profile interceptor.
  5. If the interceptor preHandle class () method returns a value of true [], the program will continue to perform the method of the processor down.

Second, determine the question

  1. In implementing user logon rights verification, we need to define a login interceptors, and login control in postHandle interceptor () method to write the business logic. (×)
  2. When configuring the interceptor, the attribute value of the path must be set to / **. (×)
  3. A plurality of interceptors, postHandle () method and afterCompletion () method will be executed in accordance with the order of arrangement. (×)
  4. Global interceptors and interceptor specified path can not be simultaneously configured, otherwise it will error runtime. (×)
  5. mvc: child elements interceptor can write in any position. (×)

Third, the multiple-choice questions

  1. The following information about Spring MVC configuration file interceptor configuration errors saying yes. (B)
    A: To use Spring MVC interceptor, first need to configure a custom interceptor in the configuration file.
    B: mvc: interceptors element is used to configure a set of interceptors that are child elements defined in the interceptor specified path.
    C: mvc: interceptors can configure multiple elements mvc: interceptor child element.
    D: mvc: exclude-mapping element does not need to configure a path for the intercepted request.
  2. The method does not belong to the following classes of interceptor Yes. (D)
    A: preHandler ()
    B: The postHandle ()
    C: afterCompletion ()
    D: afterpletion ()
  3. Which of the following methods can be defined in Spring MVC interceptors. (D)
    A: Inheritance HandlerInterceptor from
    B: realized WebRequestInterceptor
    C: implement the cunningly named HandlerInterceptorAdapter
    D: Inheritance WebRequestInterceptor
  4. Following the flow of execution on the interceptor to say the wrong yes. (C)
    A: The preHandle program will first execute () method of class interceptor.
    B: If the return value is true preHandle () method, the program will continue execution in the processor-down, or down will not be executed.
    C: After the service processor (i.e., the Controller class) request has been handled, executes The preHandle () method.
    D: After the request has been handled DispatcherServlet will be performed afterCompletion () method.
  5. About user permissions verification of the implementation process, saying the wrong yes. (D)
    A: Only after the user logged in to access the main page in the system.
    B: If you do not log in to directly access the main page, the interceptor will intercept the request and forwarded to the login page.
    C: If a user name or password error, will give the appropriate message on the login page.
    D: When a user is logged in, click the "Sign out" link in the system home page, the system will return to the main page.

Fourth, the short answer questions

  1. Please briefly describe the method interceptor HandlerInterceptor interface and do explain.
    HandlerInterceptor interface has three methods:
    preHandler () method: This method is performed before controller method, the interrupt return value indicates whether the subsequent operation. When it returns a value of true, indicating that it goes; when the return value is false, will break all the subsequent operations.
    The postHandle () method: This method calls the method after the controller, and a view before analysis execution. This method can make further modifications to the model and view requests domain.
    afterCompletion () method: This method throughout the request is complete, i.e., after the execution view rendering. You can achieve some resource cleanup, logs and other information to work through this method.

Finishing is not easy, if help support your thumbs!

Published 19 original articles · won praise 2 · Views 543

Guess you like

Origin blog.csdn.net/weixin_46218781/article/details/104427351