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

Deciding filter mapping

Defining the mapping method is crucial to implementing the intercepting filter pattern. This is because a bad method for mapping can impact the project directly and cause rework. We have two filter mapping types—UrlPattern and servlet name.

The use of UrlPatterns is indicated when we want to filter the HTTP Requests to non-specific resources or files, but we also want to filter various unknown resources. Here are some examples of this:

  • *.jsp: This filters all requests to JSP pages. If one JSP page is added to the server, then the filter will filter the new JSP page without making any modifications.
  • /*: This filters all requests to all resources or files on the server. If one resource or file is added to the server, then the filter will filter this new resource or file without performing any modifications.
  • /user/*: This filters all requests to all resources or files on the server that have a URI beginning with /user. If one resource or file that is accessed by a URI beginning with /user is added on servlet, then the filter will filter this new resource or file without performing any modifications.

The servlet name used to map the filter indicates when you want to filter a specific servlet, independent of its urlPattern. This way of mapping allows us to modify one urlPattern of the mapped servlet without performing any modifications on the filter. Here are some examples:

  • {servlet1}: This only maps the servlet named as servlet1. If the urlPatterns of servlet1 are modified, then the filter doesn't need to be modified.
  • {servlet1,servlet2}: This maps two servlets named servlet1 and servlet2. Its behavior is similar to the previous example shown, in which only one servlet was mapped.

主站蜘蛛池模板: 田阳县| 和静县| 新巴尔虎左旗| 蓬莱市| 洞口县| 宁海县| 台北县| 于田县| 班玛县| 赤水市| 五原县| 遂川县| 呼玛县| 会理县| 德格县| 全南县| 修文县| 武强县| 常宁市| 环江| 镇平县| 霸州市| 禹州市| 扎囊县| 房产| 铜陵市| 增城市| 大关县| 丰顺县| 万源市| 娱乐| 武山县| 同江市| 广昌县| 五大连池市| 彭州市| 雷山县| 蓬安县| 米易县| 隆昌县| 宁化县|