Extract Servlet and JSP page content using the filter

Source: Internet
Author: User

Deploy Servlet Filters

In fact, deploying filters with Web applications does not involve any complexity. You only need to include the filter class and other Web component classes, and put the web as you normally do. xml files, together with the filter definition and filter ing Declaration) are put into the Web application structure, and the Servlet container will process all other things afterwards.

Many applications of filters

Your ability to use filters in J2EE Web applications is limited by your creativity and application design skills. You can use filters wherever you are applicable to the decorative filter mode or interceptor mode. Some of the most common applications of filters are as follows:

Load: For all requests arriving at the system, the filter collects information such as the browser type, the time of the day, the forwarding URL, and logs them.

Performance: the filter decompress the content when it passes through the line and arrives at the Servlet and JSP pages, and then obtains the response content, and convert the response content to the compression format before it is sent to the client machine.

Security: filters manage authentication tokens and properly restrict access to security resources, prompting users to perform authentication and/or direct them to a third party for authentication. Filters can even manage the Access Control List, ACL) to provide authorization in addition to identity authentication. Putting the security logic in a filter instead of on Servlet and JSP pages provides great flexibility. During development, the filter can be closed and commented out in the web. xml file ). In production applications, the filter can be enabled again. You can also add multiple filters to increase the level of security, encryption, and denial-of-service as needed.

Session processing: mixing Servlet and JSP pages with Session processing code may cause considerable trouble. Using filters to manage sessions allows Web pages to focus on content display and delegate processing without worrying about session management details.

XSLT conversion: Whether using a mobile client or using XML-based Web Services, the ability to execute conversion between XML syntaxes without embedding logic into an application is absolutely priceless.

Adapt the filter to the MVC Architecture

Model-View-Controller, MVC) architecture is an effective design. It is now the most important design methodology, integrated into most popular Web application frameworks such as Jakarta Struts and Turbine. The filter is designed to expand the request/Response Processing stream of the MVC Architecture. Whether the request/response occurs between the client and the server, or between other components on the server, the application of the filter in the processing stream is the same. From the MVC perspective, the Scheduler component can either be included in the Controller component or work with the Controller component) forward requests to appropriate application components for processing. This makes the Controller layer the best position to include Servlet filters. By placing the filter in front of the Controller component itself, the filter can be applied to all requests, or by placing it between the Controller/scheduler and the model and the Controller, it can be applied to individual Web components.

The MVC Architecture is widely spread and has good documentation. For more information about Servlet implementation in MVC and MVC architectures, see the link in references.

  1. DoFilter method in Servlet
  2. Configure Servlet Filter
  3. Install Servlet and JSP development tools
  4. Java Servlet getting started
  5. What is a Servlet filter?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.