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

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
主站蜘蛛池模板: 万宁市| 会泽县| 盱眙县| 铜川市| 拉萨市| 姚安县| 庐江县| 枣强县| 双辽市| 庆元县| 海兴县| 宽甸| 都兰县| 巩义市| 洪洞县| 雅江县| 万年县| 中卫市| 尚志市| 青川县| 镇巴县| 星子县| 开阳县| 泽普县| 临猗县| 祁阳县| 宁陕县| 家居| 安西县| 通榆县| 德格县| 石棉县| 巧家县| 加查县| 贵德县| 澄城县| 凯里市| 邹平县| 嵊泗县| 萝北县| 栾城县|