Use of interceptors in Struts2

Source: Internet
Author: User

Interceptors are a core part of the STRUTS2 framework, and many of the framework's functions are built on interceptors. STRUTS2 uses built-in interceptors to accomplish most of the operations within the framework, and interceptors are specific implementations of AOP (aspect-oriented programming) in the STRUTS2 framework.

The following is the process of configuring a custom interceptor.

Suppose a function is required to print out the HelloWorld in the console before invoking each action, requiring the use of the Struts2 interceptor.

1. Create an action class Myaction.java and a configuration file struts.xml, such as.

2, write Myaction.java to achieve an age attribute.

3, configure struts.

4, set up an interceptor class Helloworldinterceptor.java, custom interceptors must implement interceptor excuses or inherit Abstractinterceptor class.

5. Add Interceptor settings to Struts.xml

6, write success.jsp page

7. Run the project.

The interceptor is complete.

Use of interceptors in Struts2

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.