As we all know, when we use STRUTS2 for project development, if we configure an interceptor for an action, the interceptor intercepts all the methods within that action. However, in some cases, we do not need to intercept all the methods, just want to intercept the specified method, at this time we need to use the Struts2
1. interceptor
Interceptor is one of struts2's most powerful features. It allows you to process the action or result before or after execution. At the same time, the interceptor allows you to modularize common code and use it as a reusable class. Many features of struts2 are
Custom interceptor of Struts2
Login. jsp
To customize the Interceptor, you must implement the com. opensymphony. xwork2.interceptor. Interceptor interface.
Package struts2.example. interce
The interceptor system is an important part of struts2. For the struts2 framework, it can be understood as an empty container. It is precisely a large number of built-in interceptors that have completed most of the operations of the framework.
Because the interceptor of the struts2
User Login Page login.jspTo customize the interceptor you need to implement the Com.opensymphony.xwork2.interceptor.Interceptor interfacePackage Struts2.example.interceptor;import Com.opensymphony.xwork2.actioncontext;import Com.opensymphony.xwork2.actioninvocation;import Com.opensymphony.xwork2.interceptor.interceptor;public Class Permissioninterceptor implements Inter
Interceptor
1: 1: concept: the interceptor is similar to the filter we have learned. It is the code that can be executed before and after the action is executed. Is a common technology used in Web development. For example, permission control and logging.
2: Multiple interceptor are connected together to form an interceptor
The previous blog introduced the concept of interceptors and some of the basics of Struts2 and custom interceptors, but how exactly is the interceptor applied in the actual project, perhaps you are still confused, then this blog we will come up with actual combat, but also a summary of the interceptor and application practice.
When we are doing any information ma
The "basicstack" interceptor is the core interceptor of struts2. It is called the "interceptor stack" and contains references from several interceptors in the "interceptor stack. If "Interceptor" is compared to a file, "
Let's talk about the request process of the interceptor in struts2 (simulate the general process)This document is used as a learning note for the Beijing shangxue struts2 course.What is an interceptor first? What can an interceptor do?The
First, Interceptor related knowledge1, STRUTS2 framework AnalysisHolly Version Life case:Film and television Company (filming) ActionmapperMedia company (packaging star) actionmappingStar ActionBroker Actionproxy (Agent object)The unit is located actioninvocationHandyman Interceptor (Interceptor)Recursive ==992.
Interceptors are the struts2 core, and many functions are implemented by interceptors.
I. Write a interceptor yourself
Write the interception in the Interceptor method
two. Configuring Interceptors in Struts2.xml
Write the
Note:
The interceptor
Objective
Recently developed a project, because the project in the entire development process in a hurry state (almost every project), so the project in the closing phase of the discovery of the lack of logging system log function, the previous system is directly written in the code of each module, and then deposited into the form, on the page can view some of the logs. This system does not have this requirement, so it is thought to do a system common log records, the main record data are:
The role of interceptors:The interceptor can dynamically intercept requests sent to the specified action, and through the interceptor mechanism, you can insert some code before and after the action execution to implant our logical thinking.The implementation principle of interceptors:Interceptors are invoked by proxy, by dynamically acting on our action, by inserting our interception code before and after t
Custom interceptor
1). Detailed steps
I. Define an interceptor class
> Interceptor interfaces can be implemented.> Inherit the abstractinterceptor abstract class
Ii. Define the functions of the interceptor in the Interceptor () method of the
Struts2 Interceptor
1. The Interceptor in Struts is a class that implements a class of interceptor interfaces.
2. The interceptor in struts and the filter in the servlet have similar functions, literally, the struts interceptor do
This article will introduce you to the Struts2 control interceptor. I hope this tutorial will be helpful to you.
The role of the interceptor is similar to that of the filter used for development based on the strtus framework.
Configure the default Interceptor. the interceptor
And of course there are many interceptor stacks, so let's look at the interceptor first.
Interceptor name
Aliasinterceptor
"Alias Blocker"
Configuration name
Alias
Describe
Allows parameters to use different aliases across multiple requests, which can be used to link multiple actions with different names, and
The nature of the Interceptor:An interceptor is a class, a class that implements the interceptor of a super interface. The Interceptor interface defines three methods of Init (), Destory (), intercept (). where Inercept () is the core method, the parameter of the method is invocation, and its type is the Actioninvocatio interface, which defines the core method of
perform business logic operations.
Differences between interceptor and filter:
The Interceptor is based on the Java reflection mechanism, and the filter is based on function callback.
The interceptor does not depend on the servlet container, and the filter depends on the servlet container.
The interceptor can onl
Page 1 of 2The first tutorial concentrate on creating a basic interceptor, but useful in a typical Web application.This is very common, developer wants to restrict the browser to cache rendered pages. And the the-the-the-used to achieve are having code similar to the following mostly in the JSP pages to prevent caching. Either we have this code in all the JSPs pages or more friendly A-common JSP page where we have this code an D include it in all the
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.