Java Magazine, Nov/Dec 2017
ORACLE COM JAVAMAGAZINE NOVEMBER DECEMBER 2017 20 java ee 8 example a request to file ext path and path to file ext activates the servlet with URL patterns path and ext A reference to the Servlet Mapping API is obtained from the servlets HttpServletRequest instance by calling the getHttpServletMapping method The API exposes four methods The getMatchValue method that returns the value that was matched The getPattern method that returns the URL pattern that matched the request The getMappingMatch method that returns the type of the match and is represented as an enum with one of the following values CONTEXT_ ROOT DEFAULT EXACT EXTENSION IMPLICIT PATH and UNKNOWN The getServletName method that returns the fully qualified name of the servlet that was activated with the request Listing 4 shows runtime discovery of mappings Listing 4 @ WebServlet path ext public class ServletMapping extends HttpServlet protected void doGet HttpServletRequest request HttpServlet Response response throws ServletException IOException HttpServletMapping servletMapping request getHttpServletMapping response getWriter append html body append Value Matched append servletMapping getMatchValue append br append Pattern Used
You must have JavaScript enabled to view digital editions.