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

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
主站蜘蛛池模板: 仁化县| 馆陶县| 海盐县| 徐汇区| 安溪县| 资兴市| 深水埗区| 江都市| 古丈县| 临桂县| 祁东县| 鹤壁市| 浦东新区| 吉水县| 文成县| 临海市| 阿鲁科尔沁旗| 渭南市| 永善县| 和平县| 佳木斯市| 游戏| 渭源县| 西峡县| 遵化市| 龙门县| 新民市| 公主岭市| 高平市| 呈贡县| 松江区| 南部县| 兴隆县| 松滋市| 连南| 新郑市| 尼勒克县| 临安市| 东辽县| 于都县| 蒲江县|