Interceptors, which are used in AOP (aspect-oriented programming) to intercept a method or field before it is accessed, and then add some action before or after. Interception is an implementation strategy for AOP.
The Chinese document in WebWork is interpreted as?? Interceptors are objects that dynamically intercept action calls. It provides a mechanism for developers to define code that executes before and after an action is executed, or to block execution of an action before it is executed. I
action functions are more simple. When the common function code is encapsulated in the Interceptor (Code modularization), you can configure the interceptor of the corresponding function for different actions according to the function requirements. The reusability of the functions implemented by the interceptor is improved, and the fabricated and pluggable archit
Method one uses the httpsession that the servlet comes withNote the point: httpsession should be used as a parameter of the method //log in public boolean customerlogin (HttpSession httpSession) { Httpsession.setattribute ( " customer " } // Exit Public String customerout (HttpSession HttpSession) { httpsession.removeattribute ( "Customer"); return"Login"; }Method Two: Use Spring's @sessionattributes ("Logincustomer") / /log in @Controller @SessionAttri
General web site to prevent people from malicious login (not logged in directly to the background page), will use interceptor interceptor to limit login.
Below is a small example of an interceptor login limit that helps understand and apply interceptors. The basis for intercepting in interceptors is to see if there is any user information in the session scope.
If
The 1.spring boot Interceptor is default
Handlerinterceptoradapter
Abstracthandlermapping
Userroleauthorizationinterceptor
Localechangeinterceptor
Themechangeinterceptor
2. Configuring the Spring MVC Interceptor Webmvcconfigureradapter public class Webappconfig extends Webmvcconfigureradapter 3. Implement the Add Interceptor method
AngularJS interceptor and angularjs interceptor
It is a good method to intercept an authentication request before it is sent to the server or when it is returned from the server.
For example, for authentication, if the server returns a 401 status code, the user is redirected to the logon page.
AngularJS provides a way to process the response from the global layer through the
This is a creation in
Article, where the information may have evolved or changed.
Interceptor
The GRPC server provides a interceptor function that takes precedence over the data in the request when the server receives the request and then transfers it to the specified service processing and response, similar to the middleware, which is a good place to process validation, logging, and so on.
In the example o
Action. In this way, the interceptor and Action functions are more simple. When the common function code is encapsulated in the Interceptor (Code modularization), you can configure the interceptor of the corresponding function for different actions according to the function requirements. The reusability of the functions implemented by the
Preface : For example, there is a scenario, when the user is not logged in, click on the project, the investment project will need to prompt the user to sign in, and then pop up the login page, when the user login is completed, you can manipulate the corresponding page. In this case, permission interception is required, so using interceptor is invaluable.Principle IntroductionWhen the user clicks on an action button, initiates a request to the server,
Use of the alias interceptor and the alias interceptor
In an SSH project, sometimes one Action needs to jump to another Action. There are two ways to achieve jump between actions, one is chain and the other is redirectAction. The difference between the two methods is that chain is redirected on the server, data can be shared between different actions, while redirectAction redirects to the client.
Use chain
Original,That's how we configured the Interceptor. The original configuration method combined with the new namespace mvc:interceptors configuration :Is that right???Since the registration here again causes no opensessioninviewinterceptor, no session is produced Exception So: Discard the original interceptor configuration to embrace the new method: Spring Original
Interceptor aboveNote that the action configuration, @ParentPackage need to be set to the Interceptor's package name or inheritance, or an errorThe error message is:"Unable to find interceptor class referenced by Ref-name XYZ" because the Interceptor Convention scan the action class, there is no interceptor specified
FileUploadInterceptor interceptor notes, interceptor
When the request form contains a file, the FileUploadInterception interceptor automatically applies to this file.
Form:
We can add three attributes to the action to receive files, file types, and file names. The Demo is as follows:
* package com.example; * * import java.io.File; * import com.opensymp
The filter blocker dynamically intercepts strings and entity classes to check for keywords, and changes to strings and dynamic entity classes are resubmitted.First step: New Interceptor class name and inherit ActionFilterAttribute:CustomerFilterAttribute:ActionFilterAttributeStep two: Implement in Method onactionexecutingStep three: Add [Customerfilter] above the corresponding action or class to enable interception control filtering on the action or c
constructor: Ctorf after pressing ENTER)Private ReadOnly Ibugservice _bugservice;Public Bugcontroller (Ibugservice bugservice){_bugservice = Bugservice;}}}Here are the tags that need to be filteredUsing System;Using System.Collections;Using System.Collections.Generic;Using System.Linq;Using SYSTEM.WEB.MVC;Using Microsoft.Practices.ServiceLocation;Using SaaS.Contracts.SaaS.Intern;Using SaaS.Framework.IIdentity;Using SaaS.Models.Domain.Enums;Namespace SaaS.Admin.Base{Base Controller[Customerfilte
Abstract classAbstractinterceptorImplements the interceptor interface and provides empty implementations of the init and destroy methods. If our interceptor does not need to open resources, you do not need to implement these two methods. It can be seen that it is easier to implement a custom interceptor by inheriting the abstractinterceptor abstract class.
In the
, the interceptors and the action itself are more functional.When the generic function code is encapsulated inside the Interceptor (code modularity), it is possible to configure the appropriate interceptor for different actions, depending on the function required. It improves the reusability of the functions implemented by interceptors, and implements the architecture of assembly and pluggable in disguise.
Difference and use of struts2 filter and interceptor, struts2 Filter
Java web Filter and interceptor
1.1 What is an interceptor:
Interceptor, used in AOP (Aspect-Oriented Programming) to intercept a method or field before it is accessed, and then add some operations before o
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.