官术网_书友最值得收藏!

Servlet mapping versus request mapping

The servlet mapping specifies which web container of the Java servlet should be invoked for a given URL. It maps the URL patterns to servlets. When there is a request from a client, the servlet container decides which servlet it should forward the request to based on the servlet mapping. In our case, we mapped all incoming requests to DispatcherServlet.

In contrast, request mapping guides the DispatcherServlet which controller method it needs to invoke as a response to the request based on the request path. In our case, we mapped the /welcome request path to the welcome method of the HomeController class.

Pop quiz - servlet mapping

Considering the following servlet mapping, identify the possible matching URLs:

@Override 
protected String[] getServletMappings() { 
   return new String[] { "*.do"}; 
} 
  1. http://localhost:8080/webstore/welcome
  2. http://localhost:8080/webstore/do/welcome
  3. http://localhost:8080/webstore/welcome.do
  4. http://localhost:8080/webstore/welcome/do

Considering the following servlet mapping, identify the possible matching URLs:

@Override 
protected String[] getServletMappings() { 
   return new String[] { "/"}; 
} 
  1. http://localhost:8080/webstore/welcome
  2. http://localhost:8080/webstore/products
  3. http://localhost:8080/webstore/products/computers
  4. All the above
主站蜘蛛池模板: 兴文县| 芒康县| 黄梅县| 城步| 伊通| 彰武县| 苍南县| 利辛县| 砚山县| 林甸县| 老河口市| 石林| 甘泉县| 荔波县| 延津县| 曲松县| 沂源县| 西乡县| 天峻县| 海盐县| 麻城市| 双江| 句容市| 宁乡县| 永善县| 宿州市| 亳州市| 简阳市| 司法| 集贤县| 江永县| 昌黎县| 辽源市| 五大连池市| 昭苏县| 黑河市| 中超| 浮梁县| 甘德县| 弥勒县| 福安市|