zoukankan      html  css  js  c++  java
  • Servlet中的Context Path | Servlet Path | Path Info

    |-- Context Path --|-- Servlet Path -|--Path Info--|
    http://www.myserver.com /mywebapp /helloServlet /hello
    |-------- Request URI ----------------------------|

    Remember the following three points:

    1. Request URI = context path + servlet path + path info.
    2. Context paths and servlet paths start with a / but do not end with it.
    3. HttpServletRequest provides three methods getContextPath(),
      getServletPath() and getPathInfo() to retrieve the context path,
      the servlet path, and the path info, respectively, associated with a request.

    Identifying the servlet path
    To match a request URI with a servlet, the servlet container follows a simple algorithm.
    Once it identifies the context path, if any, it evaluates the remaining part of the
    request URI with the servlet mappings specified in the deployment descriptor, in the
    following order. If it finds a match at any step, it does not take the next step.

    1 The container tries to match the request URI to a servlet mapping. If it finds a
    match, the complete request URI (except the context path) is the servlet path. In
    this case, the path info is null.
    2 It tries to recursively match the longest path by stepping down the request URI
    path tree a directory at a time, using the / character as a path separator, and determining
    if there is a match with a servlet. If there is a match, the matching part
    of the request URI is the servlet path and the remaining part is the path info.
    3 If the last node of the request URI contains an extension (.jsp, for example),
    the servlet container tries to match it to a servlet that handles requests for the
    specified extension. In this case, the complete request URI is the servlet path
    and the path info is null.
    4 If the container is still unable to find a match, it will forward the request to the
    default servlet. If there is no default servlet, it will send an error message indicating
    the servlet was not found.

    servlet path是在web.xml中配置的。
    以/开头,不能以/结尾 可以是/test /*

  • 相关阅读:
    ubuntu18.04下eclipse修改maven源为阿里源
    Java中使用队列Queue
    Redis学习笔记——Redis的基本操作
    ubuntu安装redis
    Spring Boot使用监听器Listener
    Spring Boot中在程序中获得application.properties中的值
    Spring Boot使用过滤器Filter
    基于GTID的主从架构异常处理流程
    goroutine与调度器
    使用synergyc共享键鼠
  • 原文地址:https://www.cnblogs.com/land-fill/p/13473084.html
Copyright © 2011-2022 走看看