Coffee Cram: Mock Exam Chapter 13

  1. Which are true about filters? (Choose all that apply.)

    A.

    A filter can act on only the request or response object, not both.

    B.

    The destroy method is always a container callback method.

    C.

    The doFilter method is always a container callback method.

    D.

    The only way a filter can be invoked is through a declaration in the DD.

    E.

    The next filter in a filter chain can be specified either by the previous filter or in the DD.

  2. Which are true about declaring filters in the DD? (Choose all that apply.)

    A.

    Unlike servlets, filters CANNOT declare initialization parameters.

    B.

    Filter chain order is always determined by the order the elements appear in the DD.

    C.

    A class that extends an API request or response wrapper class must be declared in the DD.

    D.

    A class that extends an API request or response wrapper class is using the Intercepting Filter pattern.

    E.

    Filter chain order is affected by whether filter mappings are declared via <url-pattern> or via <servlet-name>.

  3. Given the class UserRequest is an implementation of HttpServletRequest, and given that this method in an otherwise properly defined Filter implementation:

    20. public void doFilter(ServletRequest req,
    21.                        ServletResponse response,
    22.                        FilterChain chain)
    22.         throws IOException, ServletException {
    23.   HttpServletRequest request = (HttpServletRequest) req;
    23.   HttpSession session = request.getSession();
    25.   Object user = session.getAttribute("user");
    26.   if (user != null) {
    27.     UserRequest ureq = new UserRequest(request, user);
    28.     chain.doFilter(ureq, response);
    29.   } else {
    30.     RequestDispatcher rd = request.getRequestDispatcher("/login.jsp");
    31.     rd.forward(request, response);
    32.   }
    33. }

    Which is true?

    A.

    An exception will always be thrown if line 31 executes.

    B.

    Line 28 is invalid because request must be passed as the first argument.

    C.

    This line: chain.doFilter(request, response) must be inserted somewhere in the else block.

    D.

    This method does not properly implement Filter.doFilter() because the method signature is incorrect.

    E.

    None of the above.

  4. Given a partial deployment descriptor:

    11.  <filter>
    12.     <filter-name>My Filter</filter-name>
    13.     <filter-class>com.example.MyFilter</filter-class>
    14.  </filter>
    15.  <filter-mapping>
    16.      <filter-name>My Filter</filter-name>
    17.      <url-pattern>/my</url-pattern>
    18.  </filter-mapping>
    19.  <servlet>
    20.    <servlet-name>My Servlet</servlet-name>
    21.    <servlet-class>com.example.MyServlet</servlet-
    class>
    22.  </servlet>
    23.  <servlet-mapping>
    24.    <servlet-name>My Servlet</servlet-name>
    25.    <url-pattern>/my</url-pattern>
    26.  </servlet-mapping>

    Which is true? (Choose all that apply.)

    A.

    The file is invalid because the URL pattern /my is mapped to both a servlet and a filter.

    B.

    The file is invalid because neither the servlet name nor the filter name is allowed to contain spaces.

    C.

    The filter MyFilter will be invoked after the MyServlet servlet for each request that matches the pattern /my.

    D.

    The filter MyFilter will be invoked before the MyServlet servlet for each request that matches the pattern /my.

    E.

    The file is invalid because the <filter> element must contain a <servlet-name> element that defines which servlet the filter should be applied to.

  5. Which about filters are true? (Choose all that apply.)

    A.

    Filters may be used to create request or response wrappers.

    B.

    Wrappers may be used to create request or response filters.

    C.

    Unlike servlets, all filter initialization code should be placed in the constructor since there is no init() method.

    D.

    Filters support an initialization mechanism that includes an init() method that is guaranteed to be called before the filter is used to handle requests.

    E.

    A filter’s doFilter() method must call doFilter() on the input FilterChain object in order to ensure that all filters have a chance to execute.

    F.

    When calling doFilter() on the input FilterChain, a filter’s doFilter() method must pass in the same ServletRequest and ServletResponse objects that were passed into it.

    G.

    A filter’s doFilter() may block further request processing.

  6. Which are true about the servlet Wrapper classes? (Choose all that apply.)

    A.

    They provide the only mechanism for wrapping ServletResponse objects.

    B.

    They can be used to decorate classes that implement Filter.

    C.

    They can be used even when the application does NOT support HTTP.

    D.

    The API provides wrappers for ServletRequest, ServletResponse, and FilterChain objects.

    E.

    They implement the Intercepting Filter pattern.

    F.

    When you subclass a wrapper class, you must override at least one of the wrapper class’s methods.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset