Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Servlet Filter

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

Filter:

Filter in Java is not a standard Servlet. It cannot handle user requests or generate responses to clients. It is mainly used for pre-processing of HttpServletRequest and post-processing of HttpServletResponse, which is a typical processing chain.

The advantage of the filter chain is that it can be interrupted at any time during execution, and subsequent filters and requests will not be executed as long as chain.doFilter () is not executed.

1. Filter driver:

When the web application starts, the web server creates each registered Filter instance object based on the configuration information in the web.xml file and saves it in the server's memory

HelloFilter

Com.jalja.filter.HelloFilter

HelloFilter

/ freeMark

2. Filter API:

/ / destory () is called before the Web container unloads the Filter object. This method is executed only once in the life cycle of the Filter. In this method, you can release the resources used by the filter.

Public void destroy ()

/ / execution of Filter chain

/ / chain.doFilter (request, response); / / pass the request to the next filter, and if the filter is the last filter of the filter chain, send the request to the target resource

Public void doFilter (ServletRequest request, ServletResponse response,FilterChain chain)

/ / the init method similar to servlet is called when the Filter object is created, only once, and initializes the current filter. Filter singleton

/ / FilterConfig is similar to servletConfig to obtain initialization parameter information of Filter.

Public void init (FilterConfig filterConfig)

3. Filter intercept sequence:

When multiple filter are configured in web.xml, the filter chain is formed, and their interception order depends on the order.

4. Filter filters request resources by default. If it is a request in other ways, the filter is invalid. If you want to use it, you need to add it in to specify the filtering method.

REQUEST

FORWARD

INCLUDE

ERROR

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report