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

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
主站蜘蛛池模板: 文安县| 怀化市| 宁河县| 石嘴山市| 旬阳县| 祁阳县| 兰坪| 新余市| 稷山县| 洛川县| 普陀区| 博乐市| 太白县| 柞水县| 泾川县| 寻乌县| 五原县| 十堰市| 桂阳县| 竹溪县| 府谷县| 广德县| 平邑县| 吉林市| 鹤岗市| 桃源县| 株洲市| 丹凤县| 开化县| 苍梧县| 盘山县| 正安县| 团风县| 呼图壁县| 安陆市| 蛟河市| 丹寨县| 本溪| 格尔木市| 宣威市| 旺苍县|